Commit 06d54cfd authored by shangbj's avatar shangbj

增加本地api

parent e20b33a6
const express = require('express')
// Create express instnace
const app = express()
// Require API routes
const users = require('./routes/users')
// Import API Routes
app.use(users)
// Export the server middleware
module.exports = {
path: '/api',
handler: app
}
\ No newline at end of file
const { Router } = require('express')
const router = Router()
// Mock Users
const users = [
{ name: 'Alexandre' },
{ name: 'Pooya' },
{ name: 'Sébastien' }
]
/* GET users listing. */
router.get('/users', function (req, res, next) {
res.json(users)
})
/* GET user by ID. */
router.get('/users/:id', function (req, res, next) {
const id = parseInt(req.params.id)
if (id >= 0 && id < users.length) {
res.json(users[id])
} else {
res.sendStatus(404)
}
})
module.exports = router
\ No newline at end of file
......@@ -60,6 +60,10 @@ module.exports = {
** Customize the progress bar color
*/
loading: { color: '#73A7E1' },
serverMiddleware: [
// API middleware
'~/api/index.js'
],
/*
** Build configuration
*/
......
......@@ -2420,7 +2420,7 @@ expand-brackets@^2.1.4:
snapdragon "^0.8.1"
to-regex "^3.0.1"
express@^4.16.2:
express@^4.16.2, express@^4.16.3:
version "4.16.3"
resolved "https://registry.yarnpkg.com/express/-/express-4.16.3.tgz#6af8a502350db3246ecc4becf6b5a34d22f7ed53"
dependencies:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment