Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
liangminjian@itouchtv.cn committed Jul 20, 2018
0 parents commit fa4b98f
Show file tree
Hide file tree
Showing 20 changed files with 1,172 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
log
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
features

* valid request
* jwt
- auto refresh
* log
* cors
* discover
40 changes: 40 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const express = require('express');
const bodyParser = require('body-parser');
const { messageError } = require('./src/utils/errorHandle');

const config = require('./src/config');
const {
filter,
auth,
jwt,
cors,
log,
monitor
} = require('./src/middleware');

const app = new express();

app.use(filter);
app.use(monitor);
app.use(bodyParser.json());
app.use(bodyParser.text({ type: '*/xml' }));
app.use(bodyParser.urlencoded({ extended: true }));

app.use(log);
app.use(cors);
app.use(auth);
app.use(jwt);
app.use((req, res, next) => {
next(messageError('NotFound', req.url));
});

app.use((err, req, res, next) => {
const { code = -1, message } = err;
res.status(err.status).json({ code, message });
});

app.listen(config.PORT);

process.on('unhandledRejection', err => {
console.log('Unhandled Rejection: ', err)
});
Loading

0 comments on commit fa4b98f

Please sign in to comment.