File tree 16 files changed +63
-67
lines changed
16 files changed +63
-67
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- lib-cov
2
- * .seed
3
- * .log
4
- * .csv
5
- * .dat
6
- * .out
7
- * .pid
8
- * .gz
9
-
10
- pids
11
- logs
12
- results
13
- _dev
14
- bower_components
15
-
16
- npm-debug.log
17
- node_modules
18
- server_old
19
- public
20
-
21
- # OS generated stuff
1
+ /dist
2
+ /logs
3
+ /npm-debug.log
4
+ /node_modules
22
5
.DS_Store
23
- .DS_Store ?
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
The MIT License (MIT)
2
2
3
- Copyright (c) 2015 Jason Miller
3
+ Copyright (c) 2016 Jason Miller
4
4
5
5
Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
this software and associated documentation files (the "Software"), to deal in
Original file line number Diff line number Diff line change @@ -26,11 +26,11 @@ rm -rf .git && git init && npm init
26
26
# Install dependencies
27
27
npm install
28
28
29
- # Run it
30
- PORT=8080 npm start
29
+ # Start development live-reload server
30
+ PORT=8080 npm run dev
31
31
32
- # With nodemon :
33
- PORT=8080 nodemon
32
+ # Start production server :
33
+ PORT=8080 npm start
34
34
```
35
35
36
36
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " express-es6-rest-api" ,
3
- "version" : " 0.2.2 " ,
3
+ "version" : " 0.3.0 " ,
4
4
"description" : " Starter project for an ES6 RESTful Express API" ,
5
- "main" : " index.js " ,
5
+ "main" : " dist " ,
6
6
"scripts" : {
7
- "start" : " babel-node index.js" ,
8
- "test" : " echo \" Error: no test specified\" && exit 1"
7
+ "dev" : " nodemon -w src --exec 'babel-node src --presets es2015,stage-0'" ,
8
+ "build" : " babel src -s -D -d dist --presets es2015,stage-0" ,
9
+ "start" : " node dist" ,
10
+ "prestart" : " npm run -s build" ,
11
+ "test" : " eslint src"
9
12
},
10
- "repository" : {
11
- "type" : " git" ,
12
- "url" : " git://github.com/developit/express-es6-rest-api.git"
13
+ "eslintConfig" : {
14
+ "extends" : " eslint:recommended" ,
15
+ "parserOptions" : {
16
+ "ecmaVersion" : 7 ,
17
+ "sourceType" : " module"
18
+ },
19
+ "env" : {
20
+ "node" : true
21
+ },
22
+ "rules" : {
23
+ "no-console" : 0 ,
24
+ "no-unused-vars" : 1
25
+ }
13
26
},
27
+ "repository" : " developit/express-es6-rest-api" ,
14
28
"author" :
" Jason Miller <[email protected] >" ,
15
- "license" : " Proprietary " ,
29
+ "license" : " MIT " ,
16
30
"dependencies" : {
17
31
"body-parser" : " ^1.13.3" ,
18
32
"compression" : " ^1.5.2" ,
23
37
"devDependencies" : {
24
38
"babel-cli" : " ^6.9.0" ,
25
39
"babel-core" : " ^6.9.0" ,
26
- "babel-preset-es2015" : " ^6.9.0"
40
+ "babel-preset-es2015" : " ^6.9.0" ,
41
+ "babel-preset-stage-0" : " ^6.5.0" ,
42
+ "eslint" : " ^3.1.1" ,
43
+ "nodemon" : " ^1.9.2"
27
44
}
28
45
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
import resource from 'resource-router-middleware' ;
2
2
import facets from '../models/facets' ;
3
3
4
- export default resource ( {
4
+ export default ( { config , db } ) => resource ( {
5
5
6
6
/** Property name to store preloaded entity on `request`. */
7
7
id : 'facet' ,
@@ -10,7 +10,7 @@ export default resource({
10
10
* Errors terminate the request, success sets `req[id] = data`.
11
11
*/
12
12
load ( req , id , callback ) {
13
- var facet = facets . find ( facet => facet . id === id ) ,
13
+ let facet = facets . find ( facet => facet . id === id ) ,
14
14
err = facet ? null : 'Not found' ;
15
15
callback ( err , facet ) ;
16
16
} ,
Original file line number Diff line number Diff line change
1
+ import { version } from '../../package.json' ;
1
2
import { Router } from 'express' ;
2
3
import facets from './facets' ;
3
4
4
- export default function ( ) {
5
- var api = Router ( ) ;
5
+ export default ( { config , db } ) => {
6
+ let api = Router ( ) ;
6
7
7
8
// mount the facets resource
8
- api . use ( '/facets' , facets ) ;
9
+ api . use ( '/facets' , facets ( { config , db } ) ) ;
9
10
10
11
// perhaps expose some API metadata at the root
11
12
api . get ( '/' , ( req , res ) => {
12
- res . json ( {
13
- version : '1.0'
14
- } ) ;
13
+ res . json ( { version } ) ;
15
14
} ) ;
16
15
17
16
return api ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "port" : 8080 ,
3
+ "bodyLimit" : " 100kb" ,
4
+ "corsHeaders" : [" Link" ]
5
+ }
Original file line number Diff line number Diff line change
1
+ export default callback => {
2
+ // connect to a database if needed, the pass it to `callback`:
3
+ callback ( ) ;
4
+ }
Original file line number Diff line number Diff line change @@ -2,32 +2,33 @@ import http from 'http';
2
2
import express from 'express' ;
3
3
import cors from 'cors' ;
4
4
import bodyParser from 'body-parser' ;
5
- import db from './db' ;
5
+ import initializeDb from './db' ;
6
6
import middleware from './middleware' ;
7
7
import api from './api' ;
8
+ import config from './config.json' ;
8
9
9
- var app = express ( ) ;
10
+ let app = express ( ) ;
10
11
app . server = http . createServer ( app ) ;
11
12
12
13
// 3rd party middleware
13
14
app . use ( cors ( {
14
- exposedHeaders : [ 'Link' ]
15
+ exposedHeaders : config . corsHeaders
15
16
} ) ) ;
16
17
17
18
app . use ( bodyParser . json ( {
18
- limit : '100kb'
19
+ limit : config . bodyLimit
19
20
} ) ) ;
20
21
21
22
// connect to db
22
- db ( λ => {
23
+ initializeDb ( db => {
23
24
24
25
// internal middleware
25
- app . use ( middleware ( ) ) ;
26
+ app . use ( middleware ( { config , db } ) ) ;
26
27
27
28
// api router
28
- app . use ( '/api' , api ( ) ) ;
29
+ app . use ( '/api' , api ( { config , db } ) ) ;
29
30
30
- app . server . listen ( process . env . PORT || 8080 ) ;
31
+ app . server . listen ( process . env . PORT || config . port ) ;
31
32
32
33
console . log ( `Started on port ${ app . server . address ( ) . port } ` ) ;
33
34
} ) ;
File renamed without changes.
Original file line number Diff line number Diff line change 1
1
import { Router } from 'express' ;
2
2
3
- export default function ( ) {
4
- var routes = Router ( ) ;
3
+ export default ( { config , db } ) => {
4
+ let routes = Router ( ) ;
5
5
6
6
// add middleware here
7
7
Original file line number Diff line number Diff line change 1
1
// our example model is just an Array
2
- var facets = [ ] ;
2
+ const facets = [ ] ;
3
3
export default facets ;
You can’t perform that action at this time.
0 commit comments