example-single-process
v1.0.1
Published
An example implementation of an Oddworks server in a single process.
Downloads
3
Readme
Oddworks Example Server - Single Process
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:
- redis store
- redis-search store
- catalog service
- events service - with the google-analytics analyzer
- identity service
- json-api service
*Note: We're using fakeredis and make no guarantees about your data here. You would probably not want to use this in production.
Deploy It!
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.
Setup
After you've cloned this repo locally, follow these steps to get it running.
Install node modules
$ npm install
Environment Variables
You can override the default values we use, or run the server as-is.
NODE_ENV
- this environment variable will tell which environment to run node in. The default value isdevelopment
.PORT
- this environment variable will tell which port to run the express server on. The default value is3000
.JWT_SECRET
- this environment variable is used as the secret used to sign your JWT tokens. The default value issecret
.DATA_DIR
- this environment variable will tell our server where to look for aseed.js
file. By default this isundefined
and we use@oddnetworks/oddworks-example-data
'snasa
seed script. Read below about Example DataGOOGLE_ANALYTICS_ID
- this environment variable is used to send event metrics into the google-analytics event analyzer. The default value isUA-XXXX-XX
.
Startup
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.
Hit the API
Once your server is running, you can begin making requests like so:
$ curl -X GET -H "x-access-token: YOUR_TOKEN_HERE" -H "Accept: application/json" "http://localhost:3000/videos"
Required Headers
x-access-token
- the value here will depend on how you deployed and your environment. See Access Tokensaccept
- the value here should always beapplication/json
Access Tokens
The default data includes one channel named nasa
and three platforms with ids of apple-ios
, apple-tv
, and roku
. In order to generate an access token for the sample data, you can use the oddworks-cli like so:
$ oddworks generate-token -c nasa -p apple-ios -j {your-jwt-secret}
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
Example Data
By default we use the nasa
seed function provided by the @oddnetworks/oddworks-example-data package.
You do not need to override example data, but if you want to:
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 DATA_DIR
environment variable, please check out the oddworks-example-data repo.
You can clone the oddworks-example-data
repo, or if you want to start working with the seed script within this project you can use the oddworks-cli and run:
$ oddworks fetch-data