-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (36 loc) · 1.35 KB
/
app.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
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var model = require('./models/model.js');
var app = new express();
//监听端口
var port = 3000;
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//app.use(express.static('dist'));
//连接数据库
//mongoose.connect('mongodb://localhost:27017/warehouse');
mongoose.connect('mongodb://localhost:27017/mongotest');
var db = mongoose.connection;
//监听数据库错误
db.on('error',function(){console.log('mongodb connection error')});
db.once('open',function(){console.log('mongodb connection sucess')});
//设置路由
// app.get('/',function(req,res){
// res.sendFile('./dist/index.html');
// });
app.get('/',function(req,res){
res.redirect('http://localhost:8080');
});
var login = require('./routers/login.js');
app.use('/api',login);
var commodity = require('./routers/commodity.js');
app.use('/api',commodity);
var clientAndSupplier = require('./routers/clientAndSupplier.js');
app.use('/api',clientAndSupplier);
var user = require('./routers/user.js');
app.use('/api',user);
var inventoryManagement = require('./routers/inventoryManagement.js');
app.use('/api',inventoryManagement);
//开始监听
app.listen(port,function(){console.log('I am listening port '+port)});