From 689bade73046ba2c35af59d7a65824a441b14a65 Mon Sep 17 00:00:00 2001 From: BoHong Li Date: Wed, 12 Apr 2017 05:56:20 +0800 Subject: refactor(app.js): Extract note action --- app.js | 21 ++++----------------- lib/web/noteRouter.js | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 lib/web/noteRouter.js diff --git a/app.js b/app.js index 2f06de94..48cb68e5 100644 --- a/app.js +++ b/app.js @@ -280,23 +280,10 @@ app.post('/uploadimage', function (req, res) { } }) }) -// get new note -app.get('/new', response.newNote) -// get publish note -app.get('/s/:shortid', response.showPublishNote) -// publish note actions -app.get('/s/:shortid/:action', response.publishNoteActions) -// get publish slide -app.get('/p/:shortid', response.showPublishSlide) -// publish slide actions -app.get('/p/:shortid/:action', response.publishSlideActions) -// get note by id -app.get('/:noteId', response.showNote) -// note actions -app.get('/:noteId/:action', response.noteActions) -// note actions with action id -app.get('/:noteId/:action/:actionId', response.noteActions) -// response not found if no any route matches + +app.use(require('./lib/web/noteRoute')) + +// response not found if no any route matxches app.get('*', function (req, res) { response.errorNotFound(res) }) diff --git a/lib/web/noteRouter.js b/lib/web/noteRouter.js new file mode 100644 index 00000000..007c02c2 --- /dev/null +++ b/lib/web/noteRouter.js @@ -0,0 +1,24 @@ +'use strict' + +const Router = require('express').Router + +const response = require('../response') + +const noteRouter = module.exports = Router() + +// get new note +noteRouter.get('/new', response.newNote) +// get publish note +noteRouter.get('/s/:shortid', response.showPublishNote) +// publish note actions +noteRouter.get('/s/:shortid/:action', response.publishNoteActions) +// get publish slide +noteRouter.get('/p/:shortid', response.showPublishSlide) +// publish slide actions +noteRouter.get('/p/:shortid/:action', response.publishSlideActions) +// get note by id +noteRouter.get('/:noteId', response.showNote) +// note actions +noteRouter.get('/:noteId/:action', response.noteActions) +// note actions with action id +noteRouter.get('/:noteId/:action/:actionId', response.noteActions) -- cgit v1.2.3