AHOPE Project on Google App Engine: Postgresql, Parse-Server, and Parse-dashboard in backend with Google Sign-in for Authentication
This project sets up Parse-server and Parse-dashboard to run Google App Engine Node.js standard environment. This project is based on the original Parse sample project
git clone https://github.com/evandana/keep-ahope-gcpcd keep-ahope-gcp
- Create a project in the Google Cloud Platform Console.
- Enable billing for your project.
- Create an OAuth2 client for your project. This is done by choosing "Create credentials" then "OAuth client ID" under the Credentials tab. Select "Web Application" as the Application type. The name of the client doesn't matter, but be sure to add to "Authorized JavaScript origins" the domain (in the format of scheme://server-address:port-number) where the app will run. Note the client id that is created.
- Install the Google Cloud SDK.
- Create a Cloud SQL instance (Postgresql flavor) in the same project, and note its cloud SQL instance connection name, such as:
ahope-parse-poc:northamerica-northeast1:ahope-poc-dbIt is simple concatenation of GCloud project name, region name, and the CloudSQL instance id, separated by colons. - In the Cloud SQL instance, create a database user (also known as a "login role" in Postgresql) and create a database that this user either owns or has all privileges.
- In config.yml file, configure properties as documented there.
- As of now, you also need to add the CloudSQL connection name (see above) to app.standard.yml, under beta_settings.cloud_sql_instances
-
Setup a Postgresql server either locally or on another host that the local dev machine can reach by TCP socket. Cloud SQL uses Postgresql 9.6. While it is recommended to use the same version when installing locally, it's unlikely for version to matter if you want to use an existing Postgresql server of a version that is close to 9.6. Collect the hostname and port number.
-
Same as setting up for cloud, create a database user and a database that this new user owns or can administer.
-
In config-dev.yml file, create/update the following properties:
- DATABASE_URI: "postgres://<db-user>:<db-password>@/<hostname:port>/<database-name>".
- SERVER_URL: "http://localhost:8080/parse"
Note that all properties in config.yml file are inherited, subject to overriding.
If you want to run Parse server locally but using the Cloud SQL in Google Cloud, you can install and run a proxy, which opens and listens on a local TCP port to receive and route Postgresql requests to the Cloud SQL instance. You should update DATABASE_URI accordingly to reflect the local host name and the port number used by the proxy. For more details see Cloud SQL Proxy.
- Follow the "Setup - Local" section above. Make sure the configuration files are set correctly.
npm installnpm start- Goto http://localhost:8080/dashboard to access the Parse Dashboard. URL http://localhost:8080/parse can be used for REST API access.
- When logging into dashboard running locally, use ahope-admin/ahope as username/password. See server.js where passwords are set for local and cloud environments.
- Note that Parse Server, when running locally but behind a corporate firewall, will likely not be able to validate an id token provided by Google Sign-in.
- See a sample page for how Google Sign-in and Parse Javascript SDK are used.
- To access the page locally, go to http://localhost:8080/static/index.html.
- Any complex business logic can be implemented as "Cloud Functions", as shown in Cloud Function, which runs on the server side.
- Make sure the necessary environment variables are set correctly. See the "Setup - Cloud (App Engine) Only" section above.
gcloud app deploy app.standard.yaml
Refer to the appengine/README.md file for more instructions on running and deploying.