-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
42 lines (34 loc) · 1.19 KB
/
app.js
File metadata and controls
42 lines (34 loc) · 1.19 KB
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
var express = require('express'), path = require('path'), url = require('url'), mvc = require('mvc'), fs = require('fs');
var app = module.exports = express.createServer(express.bodyParser())
// 配置
.configure(function () {
// 设置默认视图引擎目录
this.set('views', path.join(__dirname, "views"));
// 默认文件后缀,并为之选择视图引擎
this.set('view engine', 'txt');
this.register('txt', require('jade'));
});
// 路由 RESTfull
// SELECT
app.get(/.*/, function (req, res) {
// 入门学习使用下面这行:
// res.send(url.parse(req.url).pathname.substring(1));
// 直接使用视图引擎请查看下面这行
// res.render(url.parse(req.url).pathname.substring(1), { layout: false });
// 使用MVC模式请使用下面这行
(new mvc.context(req, res)).invoke();
});
// INSERT
app.post(/.*/, function (req, res) {
(new mvc.context(req, res)).invoke();
});
// DELETE
app.del(/.*/, function (req, res) {
(new mvc.context(req, res)).invoke();
});
// UPDATE
app.put(/.*/, function (req, res) {
(new mvc.context(req, res)).invoke();
});
// 监听端口
app.listen(process.env.PORT);