Home

Awesome

<div align="center"> <img src="/public/img/skeleton.png" alt="skeleton"> </div>

koa-skeleton

Dependency Status

An example Koa application that glues together Koa + Postgres + good defaults + common abstractions that I frequently use to create web applications.

Also used as a test bed for my own libraries.

Originally this project was intended to be forked and modified, but it's grown to the point that it's better left as a demonstration of how one can structure a Koa + Postgres application.

Deploy

The Stack

Depends on Node v8.x+:

Setup

You must have Postgres installed. I recommend http://postgresapp.com/ for OSX.

createdb koa-skeleton
git clone git@github.com:danneu/koa-skeleton.git
cd koa-skeleton
touch .env
npm install
npm run reset-db
npm run start-dev

> Server is listening on http://localhost:3000...

Create a .env file in the root directory which will let you set environment variables. npm run start-dev will read from it.

Example .env:

DATABASE_URL=postgres://username:password@localhost:5432/my-database
DEBUG=app:*
RECAPTCHA_SITEKEY=''
RECAPTCHA_SITESECRET=''

Configuration (Environment Variables)

koa-skeleton is configured with environment variables.

You can set these by putting them in a .env file at the project root (good for development) or by exporting them in the environment (good for production, like on Heroku).

You can look at src/config.js to view these and their defaults.

Evironment VariableTypeDefaultDescription
<code>NODE_ENV</code>String"development"Set to "production" on the production server to enable some optimizations and security checks that are turned off in development for convenience.
<code>PORT</code>Integer3000Overriden by Heroku in production.
<code>DATABASE_URL</code>String"postgres://localhost:5432/koa-skeleton"Overriden by Heroku in production if you use its Heroku Postgres addon.
<code>TRUST_PROXY</code>BooleanfalseSet it to the string "true" to turn it on. Turn it on if you're behind a proxy like Cloudflare which means you can trust the IP address supplied in the X-Forwarded-For header. If so, then ctx.request.ip will use that header if it's set.
<code>HOSTNAME</code>StringundefinedSet it to your hostname in production to enable basic CSRF protection. i.e. example.com, subdomain.example.com. If set, then any requests not one of `GET
<code>RECAPTCHA_SITEKEY</code>StringundefinedMust be set to enable the Recaptcha system. https://www.google.com/recaptcha
<code>RECAPTCHA_SITESECRET</code>StringundefinedMust be set to enable the Recaptcha system. https://www.google.com/recaptcha
<code>MESSAGES_PER_PAGE</code>Integer10Determines how many messages to show per page when viewing paginated lists
<code>USERS_PER_PAGE</code>Integer10Determines how many users to show per page when viewing paginated lists

Don't access process.env.* directly in the app. Instead, require the src/config.js and access them there.

Features/Demonstrations

Philosophy/Opinions

Conventions

Changelog

The following version numbers are meaningless.

License

MIT