项目作者: mattboutet

项目描述 :
Hapi API Boilerplate with basic user/auth
高级语言: JavaScript
项目地址: git://github.com/mattboutet/user-boilerplate.git
创建时间: 2016-06-05T20:07:57Z
项目社区:https://github.com/mattboutet/user-boilerplate

开源协议:

下载


User Boilerplate

A general purpose boilerplate for building APIs with hapi, with built in user model and JWT-based authentication. Based on https://github.com/devinivy/boilerplate-api

Getting Started

In this example our project is called my-project

  1. $ git clone git@github.com:mattboutet/user-boilerplate.git my-project
  2. $ cd my-project
  3. $ git remote set-url origin git@github.com:your-username/my-project.git

Now install the dependencies and start running the server

  1. $ npm install
  2. $ npm test
  3. $ NODE_ENV=dev npm start

If everything goes well you should see this

  1. > user-boilerplate@0.3.0 start /Users/matt/domains/user-boilerplate
  2. > node server
  3. Server started at http://0.0.0.0:3000

Now your app is running at http://0.0.0.0:3000

Tools

Here are a list of tools we include in the project :octocat:

Name Description
dogwater Integrates the Waterline ORM
sails-disk A local disk adapter for Waterline ORM
sails-mysql A MySQL adapter for Waterline ORM]
haute-couture File-based hapi plugin composer
glue Server composer for hapi.js
hoek Node utilities shared amongst the extended hapi universe
joi Object schema validation
bassmaster Batch request plugin for hapi
boom HTTP-friendly error objects
hapi-swagger A Swagger interface for hapi
lab Node.js test framework
labbable No-fuss hapi server testing
hapi-auth-jwt2 Secure Hapi.js authentication plugin using JSON Web Tokens

Test It Out!

Browse to http://0.0.0.0:3000/swagger

Time to make a user! Make a POST request to the users endpoint.

  1. {
  2. "email": "test@test.com",
  3. "password": "test",
  4. "firstName": "test",
  5. "lastName": "test"
  6. }

Now send a GET request to the users endpoint and you should get a response like this:

  1. [{
  2. "email": "test@test.com",
  3. "password": "$2a$10$8hoUmAcYKGcTyv.isy2xb.IYnB2KBGCytdqXHDrIfhiGZg4s8TvNa",
  4. "firstName": "Test",
  5. "lastName": "Test",
  6. "resetToken": "",
  7. "id": 1,
  8. "createdAt": "2016-06-06T01:50:37.000Z",
  9. "updatedAt": "2016-06-15T15:18:51.000Z"
  10. }]

If you POST the login route:

  1. {
  2. "email": "test@test.com",
  3. "password": "test"
  4. }

It will return a JWT that can then be used in the headers of any request to an authenticated endpoint - select the user endpoint and paste the JWT you received from the login route above into the authorization field in the Swagger-UI:

  1. {
  2. "email": "test@test.com",
  3. "password": "$2a$10$8hoUmAcYKGcTyv.isy2xb.IYnB2KBGCytdqXHDrIfhiGZg4s8TvNa",
  4. "firstName": "Test",
  5. "lastName": "Test",
  6. "resetToken": "",
  7. "id": 1,
  8. "createdAt": "2016-06-06T01:50:37.000Z",
  9. "updatedAt": "2016-06-15T15:18:51.000Z"
  10. }