-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (37 loc) · 892 Bytes
/
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
var express = require('express');
var port = 8088;
var app = express();
var router = express.Router();
router.get('/', function(req,res,next){
req.url = '/index.html';
next();
});
app.use(router);
// 接口数据
// 1、读取json数据
var goods = require("./data/goods.json")
var coment = require("./data/coment.json")
var famliy = require("./data/famliy.json")
// 2、路由
var routes = express.Router();
// 3、编写接口
routes.get('/goods', (req,res) => {
res.json(goods);
});
routes.get('/coment', (req,res) => {
res.json(coment);
});
routes.get('/famliy', (req,res) => {
res.json(famliy);
});
app.use('/api',routes);
// 定义static目录,指向./dists目录
app.use(express.static('./dists'));
// 启动express
module.express = app.listen(port, function(err){
if(err){
console.log(err);
return;
}
console.log('http://localhost:' + port + '\n');
});