-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
79 lines (68 loc) · 1.76 KB
/
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
var http = require('http'),
url = require('url'),
util = require('util'),
querystring = require('querystring'),
express = require("express"),
app = require("express").createServer();
app.configure(function(){
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(app.router);
app.use(express.static(__dirname+'/static',{maxAge:0}));
app.set('views',__dirname+'/views');
app.register('.html',require('ejs'));
app.set("view engine","html");
app.disable('view cache');
});
function start(port){
app.get('/subject/:id',function(req,res){
// console.log("id":req.params.id);i
var id = req.params.id;
if(id){
res.render('./subject/subject.html',{layout:false});
//res.send(id);
}else{
next();
}
//res.send("id:",req.params.id);
});
app.get('/api',function(req,res){
var urlObject = url.parse(req.url),pathname,query,queryObject,callback,json;
query = urlObject.query;
if(query){
queryObject = querystring.parse(urlObject.query);
callback = queryObject['callback'];
if(callback){
res.send(callback+'({test:"333"})');
}
}
});
app.get('/subject_search/:keywords',function(req,res){
var keywords = req.params.keywords;
if(keywords){
res.render('./subject_search/subject_search.html',{layout:false});
//res.send("subject_search!");
}else{
next();
}
});
app.get('/accounts/:loginid',function(req,res){
var loginid = req.params.loginid;
if(loginid){
res.render('./accounts/accounts.html',{layout:false});
//res.send('accounts!');
}else{
next();
}
});
app.get('/',function(req,res){
res.render('index.html',{layout:false});
});
app.get('/test',function(req,res){
res.send("ok");
});
app.listen(port,function(){
console.log("it works");
});
}
exports.start = start;