| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This is a quick example of an Oddworks server with all services, stores, and the API running in a single process.
This is only an example and should not be used in production. You would likely want to do things differently.
This setup uses the following oddworks stores and services:
*Note: We're using fakeredis and make no guarantees about your data here. You would probably not want to use this in production.
You can install this to Heroku as-is to get a quick reference API.
Note: Auto-deploying on Heroku will generate the JWT_SECRET environment variable.
After you've cloned this repo locally, follow these steps to get it running.
$ npm install
You can copy over .npmrc.example into your own .npmrc file to override the default values for the dev script in package.json, or run the server as-is.
Locally you can use the following command to start the server:
npm run dev
We use nodemon for development to automatically reload the server for us when file changes are detected.
{
"channel": "nasa",
"platform": "web",
"aud": [
"platform"
],
"iss": "urn:oddworks"
}Once your server is running, you can begin making requests like so:
$ curl -X GET -H "Authorization: Bearer YOUR_TOKEN_HERE" -H "Content-Type: application/json" "http://localhost:3000/config"
Required Headers
The returned JWT will be your user token for all future requests.
There are 2 types of tokens used within Oddworks. Using the Oddworks SDKs this will be handle the app loading sequence for you, but for your own knowledge you should understand how tokens are used.
The high level flow is:
First App Install
Repeated Usage
{
"channel": "nasa",
"platform": "web",
"aud": [
"platform"
],
"iss": "urn:oddworks"
}This token contains the channel and platform and is embedded into the app when you submit it to the app store. This token will only allow the device access to the /config endpoint. After hitting the /config endpoint with a platform token you will get a response that contains an automatically generated new anonymous user. This new user is saved in the user table with a new UUID. You will also get a JWT specifically for that user to use for subsequent API requests.
{
"data": {
"id": "nasa-web",
"type": "config",
"attributes": {
"features": ...,
"views": ...,
"user": {
"id": "5e3e073b-8477-4e3f-9061-a543a819cdff",
"channel": "nasa",
"type": "user"
},
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjaGFubmVsIjoibmFzYSIsInBsYXRmb3JtIjoid2ViIiwidXNlciI6IjVlM2UwNzNiLTg0NzctNGUzZi05MDYxLWE1NDNhODE5Y2RmZiIsImlhdCI6MTQ2OTcxOTEwNCwiYXVkIjpbInBsYXRmb3JtIl0sImlzcyI6InVybjpvZGR3b3JrcyJ9.SOANEq0qxkiRL5u3RCAf5glYvDAMtz9LidrLvwsnaTE"
}
}
}NOTE: You should save this JWT on the device forever to indicate that is a user on the device. The next time your app loads and it hits /config it will not generate a user since a user token was used.
{
"channel": "nasa",
"platform": "web",
"user": "12345",
"aud": [
"platform"
],
"iss": "urn:oddworks"
}This token is identical to the platform token except it contains the user ID defined in the user table that the device is making the request for. This token is required for all API calls except for /config. The reason for this is so you can track accurate user data throughout the system.
If you did not explicitly set the JWT_SECRET environment varaible, it will default to the value secret. If you deployed using the Heroku auto-deploy, this environment variable was auto-generated for you and can be found by running the following:
$ heroku config -a your-heroku-app-name | grep JWT_SECRET
We like to use jwt.io since it provides a nice interface for generating tokens.
NOTE: DO NOT submit an app to the app with a user token embedded into the app. It will yield ineffective analytics and cause you to resubmit the app to fix the problem.
By default we use the nasa() seed function provided by the @oddnetworks/oddworks-example-data package.
The configuration file relies on example data and a seed script to get running. For examples of how to set this up yourself, and override the seed script using the SEED_SCRIPT environment variable, please check out the oddworks-example-data repo.
You can clone the oddworks-example-data repo, or check out seed.js.example to get an idea of how a script might work.
| Back | FazBrowse Home | New Git URL |