-
Notifications
You must be signed in to change notification settings - Fork 49
/
app.js
48 lines (35 loc) · 1 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
47
48
var express = require('express');
var bodyParser = require('body-parser');
var config = require('./config');
var lessonConfig = require('./lesson');
var login = require('./routes/login');
var user = require('./routes/user');
var todos = require('./routes/todos');
var app = express();
var port = config.port;
app.use(bodyParser.json());
app.get('/', function (req, res) {
res.send("<h1>Hello World! This Class is called '" + lessonConfig.lesson + "'. Teacher is " + lessonConfig.teacher + ".</h1>");
});
app.use('/login', login);
app.use('/user', user);
app.use('/todos', todos);
app.use(function(req, res, next) {
res.status(404).json({
error: '资源未找到'
});
});
app.use(function(error, req, res, next) {
console.log(error);
res.status(500).json({
error: '服务器内部错误'
});
});
app.listen(port, function(error) {
if(error) {
console.log('error!');
}
else {
console.log("Server start! Listening on localhost:" + port);
}
});