项目作者: hongymagic

项目描述 :
Koa2 API template with passport, GraphQL, flowtype, knex and more.
高级语言: JavaScript
项目地址: git://github.com/hongymagic/k2.git
创建时间: 2017-05-23T12:25:29Z
项目社区:https://github.com/hongymagic/k2

开源协议:

下载


K2

K2

Build Status codecov Package dependencies Codacy Badge

Koa 2 and GraphQL server that just works™. We’ve climbed the mountain of
boilerplate for you, so you don’t have to.

Included…

  • koa2 - write stuff in middleware
  • babel - use latest ES6/7 features today. why wait?
  • passport.js - easy authentication
  • knex.js - documentation is better than sequelize
  • GraphQL - it’s the way to go
  • Jest - don’t let tests get in your way
  • ramda - please don’t use lodash or underscore
  • prettier - don’t worry about formatting…
  • flowtype - get your types right

Getting started

Make sure you have Docker installed as PostgreSQL is run on the docker
container.

  1. git clone -o k2 -b master --single-branch https://github.com/hongymagic/k2.git example-api
  2. cd example-api # Change current directory to the newly created one
  3. yarn install # Install required packages via yarn
  4. cp .env.sample .env # Configuration on development mode is done via dotenv
  5. yarn migrate:latest # Run database migrations
  6. yarn seed:run # Add some seed data
  7. yarn start:dev # Start the server in development mode

By default the API server starts on port 5000, http://localhost:5000.

Structure

  1. ┌── .env.sample # Sample .env file loaded into process.env
  2. ├── docker-compose.yml # Auxiliary services such as postgresql via docker
  3. ├── knexfile.js # Configuration for knex.js
  4. ├── migrations/ # Database migrations. See below for more info
  5. ├── seeds/ # Database seeds. See below for more info
  6. ├── tests/ # Integration tests using supertest
  7. ├── sqlite3/ # SQLite3 database location
  8. └── src/
  9. ├── db.js # DB instance used by the app and/or models
  10. ├── models/ # ORM models written in ES6 classes
  11. ├── middleware/ # Custom middleware to be used by modules
  12. ├── modules/ # Route-Controller pair for koa2
  13. ├── auth/ # Sample /authenticate module
  14. ├── graphql/ # GraphQL
  15. └── index.js # Don't touch this
  16. ├── passport.js # Passport.js configuration using passport-local
  17. ├── DataLoader.js # Data fetching layer for GraphQL
  18. ├── schema.js # GraphQL schema
  19. └── types/ # GraphQL types

Testing

K2 uses Facebook Jest so you can add a
directory named __tests__ at any level and start writing tests.

Root level tests directory is reserved for integration tests using supertest.
Currently requires you to run the database server via docker-compose: see above.

  1. yarn test # Run all tests including unit and integration tests
  2. yarn test:unit # Only run unit tests inside src/ directory
  3. yarn test:integration # Only run integration tests inside tests/ directory
  4. yarn test:coverage # Generate coverage report. Also travis default

Deployments

This is a standard Node.js version 8.0+ application. You can deploy it to
anywhere you like including, but not limited to:

Now.sh

Deploying to now is super simple if you’re using SQLite3 (default). Just run:

  1. now

AWS ElasticBeanstalk

Simply create a version of AWS EB with Node version 8.0.1 and deploy. I
personally have travis CI deploy it via a eb script.

  • TODO: Sample .ebextensions/
  • Database is already configured to prefer RDS_{HOSTNAME,DB_NAME,USERNAME,PASSWORD} connection information