vue--express启动数据服务

来源:互联网 发布:linux 设置ip 编辑:程序博客网 时间:2024/06/05 21:52

记录一下配置

build->dev.sever.js配置

var apiServer = express()var bodyParser = require('body-parser')apiServer.use(bodyParser.urlencoded({ extended: true }))apiServer.use(bodyParser.json())var apiRouter = express.Router()var fs = require('fs')apiRouter.route('/:apiName').all(function (req, res) {  fs.readFile('./db.json', 'utf8', function (err, data) {    if (err) throw err    var data = JSON.parse(data)    if (data[req.params.apiName]) {      res.json(data[req.params.apiName])      }    else {      res.send('no such api name')    }  })})apiServer.use('/api', apiRouter);apiServer.listen(port + 1, function (err) {  if (err) {    console.log(err)    return  }  console.log('Listening at http://localhost:' + (port + 1) + '\n')})

config->index.js配置

 proxyTable: {        '/api/':'http://localhost:8081/'    },
原创粉丝点击