-
Notifications
You must be signed in to change notification settings - Fork 39
/
server.js
42 lines (35 loc) · 1.04 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
var express = require('express');
var app = express();
var server = require('http').createServer(app),
url = require('url'),
path = require('path'),
fs = require('fs');
var getDemoConfig = function (req, res) {
function answer(code, data) {
res.writeHead(code,{
'Content-Type':'application/json;charset=utf-8',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Headers':'X-Requested-With'
});
res.end(data);
}
fs.readFile('./demo/demo.config.json', function(err, data) {
if (err) answer(404, '');
else answer(200, data);
});
};
app.configure(function () {
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.errorHandler());
app.use(express.static(__dirname));
app.use(app.router);
app.get('/api/demo-config', getDemoConfig);
app.get('/api/demo-config-2', getDemoConfig);
});
module.exports = server;
// Override: Provide an "use" used by grunt-express.
module.exports.use = function () {
app.use.apply(app, arguments);
};