refactor(app.js): Extract note action

This commit is contained in:
BoHong Li 2017-04-12 05:56:20 +08:00 committed by Raccoon Li
parent e2ac73f5a3
commit 689bade730
2 changed files with 28 additions and 17 deletions

21
app.js
View file

@ -280,23 +280,10 @@ app.post('/uploadimage', function (req, res) {
} }
}) })
}) })
// get new note
app.get('/new', response.newNote) app.use(require('./lib/web/noteRoute'))
// get publish note
app.get('/s/:shortid', response.showPublishNote) // response not found if no any route matxches
// 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.get('*', function (req, res) { app.get('*', function (req, res) {
response.errorNotFound(res) response.errorNotFound(res)
}) })

24
lib/web/noteRouter.js Normal file
View file

@ -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)