From 706df11e2356bd7548bfa14316e86111b7ba9d90 Mon Sep 17 00:00:00 2001 From: BoHong Li Date: Wed, 12 Apr 2017 05:48:55 +0800 Subject: [PATCH] refactor(app.js): Extract history api --- app.js | 12 +----------- lib/web/historyRouter.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 lib/web/historyRouter.js diff --git a/app.js b/app.js index cd645379..36846440 100644 --- a/app.js +++ b/app.js @@ -199,18 +199,8 @@ app.set('view engine', 'ejs') app.use(require('./lib/web/baseRouter')) app.use(require('./lib/web/statusRouter')) app.use(require('./lib/web/auth')) +app.use(require('./lib/web/historyRouter')) -var history = require('./lib/history.js') -// get history -app.get('/history', history.historyGet) -// post history -app.post('/history', urlencodedParser, history.historyPost) -// post history by note id -app.post('/history/:noteId', urlencodedParser, history.historyPost) -// delete history -app.delete('/history', history.historyDelete) -// delete history by note id -app.delete('/history/:noteId', history.historyDelete) // get me info app.get('/me', function (req, res) { if (req.isAuthenticated()) { diff --git a/lib/web/historyRouter.js b/lib/web/historyRouter.js new file mode 100644 index 00000000..738e409d --- /dev/null +++ b/lib/web/historyRouter.js @@ -0,0 +1,19 @@ +'use strict' + +const Router = require('express').Router + +const {urlencodedParser} = require('./utils') +const history = require('../history.js') + +const historyRouter = module.exports = Router() + +// get history +historyRouter.get('/history', history.historyGet) +// post history +historyRouter.post('/history', urlencodedParser, history.historyPost) +// post history by note id +historyRouter.post('/history/:noteId', urlencodedParser, history.historyPost) +// delete history +historyRouter.delete('/history', history.historyDelete) +// delete history by note id +historyRouter.delete('/history/:noteId', history.historyDelete)