skycli
installed and configured properly. If not, follow this to set it up.skycli
app creation command and give the new app a name. It's better to prefix you app name with your name or alias like your GitHub ID, since Skygear cluster is shared among everyone who has an account and it's likely someone has already taken the app name nodeblog
.nodeblog
app.__APP_NAME__
with your app's name:skycli
will look for a skygear.yaml at the current directory. Once located, it will deploy the directory and the code inside to Skygear under the app name provided at line 1 in skygear.yaml
.__API_ENDPOINT__
and __API_KEY__
with app's endpoint and api key you have jotted down:./frontend/static/main.js
:skygear.auth.signup
and skygear.auth.login
take a tuple of email and password, which will be submitted Auth gear to perform sign-up and log-in operations.gotToWriteBlogs()
. Otherwise, error message will be shown.skygear.auth.logout()
as we will invalidate the current access token. This prevents us from being attacked with reused access tokens.skygear.yaml
is the primary configuration file telling Skygear how your app is formed with (micro)services, how they are declared and what resources such as Secrets and environment variables they will use../skygear.yaml
:backend
and frontend
, while the same words at line 4 and 13 are the services' respective names. Them services will both be built with Skygear's pre-configured containerization templates nodejs:12
, as declared at line 7 and 16. path
will be the actual API endpoint others can reach the service. So the endpoint for service frontend
will be https://<your_name>-nodeblog.skygearapp.com/
whereas that for backend
will be https://<your_name>-nodeblog.skygearapp.com/api/
.MONGO_DB_URL
carrying the MongoDB's connection string is passed to the service backend
as an environment variable, as shown in line 10-12.after_user_create
, which will be triggered once a user is created on Auth gear. Code hooked to it is in /api/after_user_create
which we will cover later../backend/api.js
, which we won't be covering. They interact with the MongoDB and create/return corresponding blog payloads../frontend/static/main.js
:backend
service is registered in the Skygear app under the path /api
. Another feature of Skygear JS SDK is the app's endpoint will automatically be prepended for you, so that you can call microservices directly by their path. The current user's access token along with some other headers and payloads will be substituted into the request for you as well.fetch_blogs
in our backend service, we can simply use the wrapped fetch method with api/fetch_blogs
as the first parameter.curl
, but in that case you will have to fill in the headers and some required information yourself../backend/api.js
:MONGO_DB_URL
../skygear.yaml
:after_user_create
in the app's configuration. The user-storing functions will then get triggered when such event happens on Auth gear.