1.0.1 • Published 8 years ago

example-single-process v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
8 years ago

Oddworks Example Server - Single Process

slack.oddnetworks.com

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.

Deploy It!

You can install this to Heroku as-is to get a quick reference API.

Deploy

	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 is development.
  • PORT - this environment variable will tell which port to run the express server on. The default value is 3000.
  • JWT_SECRET - this environment variable is used as the secret used to sign your JWT tokens. The default value is secret.
  • DATA_DIR - this environment variable will tell our server where to look for a seed.js file. By default this is undefined and we use @oddnetworks/oddworks-example-data's nasa seed script. Read below about Example Data
  • GOOGLE_ANALYTICS_ID - this environment variable is used to send event metrics into the google-analytics event analyzer. The default value is UA-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 Tokens
  • accept - the value here should always be application/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