Demonstrates REST API endpoints for the angular-spa-browserify-example client.
This API server is built on top of the express-api-server module, which provides built-in web security, error handling, and logging.
It is part of a set of separate Node.js microservices (Static Web Server, Chat Server, Reverse Proxy) to demonstrate a Single Page Web Application stack end-to-end, and is designed with portability and scalability in mind (see Twelve Factors).
Configuration options are passed in by the consumer or via environment variables at runtime.
- /auth: OAuth endpoints for login and JWT token refresh.
- /logs: Client to server logging.
- /todos: Example todo lists resource.
- Install Node.js
- Install Gulp:
npm -g i gulp
- Clone this repo
- Install dependencies:
npm i
- Start the app in dev mode:
npm run dev
- Point browser to http://localhost:3000/
After installation, the following actions are available:
npm run dev
: Builds for development, runs a local webserver, and watches for changes.npm test
: Runs TypeScript file linting and unit tests once.karma start
: Runs unit tests continuously, watching for changes.npm run build
: Creates production client assets under thedist/
folder, for deployment with a static webserver or CDN.
And run your server.js
with optional runtime environment variables:
$ NODE_ENV=production API_SSL=1 API_PORT=443 node src/api-server.js
See src/config.js for configuration options to override.
API_BASE_URL
: Base url path for all endpoints (default: "/api").API_USE_CLUSTER
: Use a node cluster module (throng) to create processes per CPU core.API_HEAPDUMP
: Enableheapdump
support (trigger dumps viakill -USR2 {pid}
).API_RDB_CONN
: RethinkDB connection string.API_JWT_SECRET
: JSON Web Token Hash Secret. NOTE: You'll want to ensure this is unique per environment.API_REV_PROXY
: The server is behind a reverse proxy when set to "1".API_PORT
: The port to run on (default: 8000).API_SSL
: Use a HTTPS server when set to "1". Enforces HTTPS by redirecting HTTP users when used with a reverse HTTP/HTTPS proxy.API_SSL_KEY
: Path to the SSL key file.API_SSL_CERT
: Path to the SSL cert file.
The functionality has been implemented by integrating the following 3rd-party tools and libraries:
- Express: Fast, minimalist web framework for node
- Helmet: Secure Express apps with various HTTP headers
- Gulp: Streaming build system and task runner
- Node.js: JavaScript runtime environment for server-side development
- Mocha: The fun, simple, flexible JavaScript test framework
- Chai: BDD/TDD assertion library for node and the browser
- Sinon: Standalone test spies, stubs and mocks for JavaScript
- Mockery: Mock Node.js module dependencies during testing
MIT License Copyright © 2015 Christopher Martin