-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathprod.server.js
85 lines (69 loc) · 1.61 KB
/
prod.server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// 启动打包后(./dist)的项目
var express = require('express')
var config = require('./config/index')
var app = express()
var router = express.Router()
var port = process.env.PORT || config.build.port
router.get("/", function (req, res, next) {
req.url = './index.html'
next()
})
app.use(router)
// 接口请求 -> 商家模块 mock
let sellerData = require('./mock/seller.json')
let indexListData = require('./mock/index-list.json')
let restaurantList = require('./mock/restaurant-list.json')
let findList = require('./mock/find-list.json')
let apiRouter = express.Router()
apiRouter.get("/seller", function (req, res) {
res.json({
// 0 -> 请求成功
code: 0,
data: sellerData.seller
})
})
apiRouter.get("/goods", function (req, res) {
res.json({
// 0 -> 请求成功
code: 0,
data: sellerData.goods
})
})
apiRouter.get("/ratings", function (req, res) {
res.json({
// 0 -> 请求成功
code: 0,
data: sellerData.ratings
})
})
apiRouter.get("/indexList", function (req, res) {
res.json({
// 0 -> 请求成功
code: 0,
data: indexListData
})
})
apiRouter.get("/restaurantList", function (req, res) {
res.json({
// 0 -> 请求成功
code: 0,
data: restaurantList
})
})
apiRouter.get("/findList", function (req, res) {
res.json({
// 0 -> 请求成功
code: 0,
data: findList
})
})
// http://localhost:8080/api/seller
app.use('/api', apiRouter)
app.use(express.static('./dist'))
module.exports = app.listen(port, function (err) {
if (err) {
console.log(err)
return
}
console.log('> Listening at ' + port + '\n')
})