-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (41 loc) · 1.39 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
var express = require('express'),
api = require('./routes/api');
var app = express();
// initial configuration
app.configure( function() {
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
app.set('view options', {
layout: false
});
//CORS middleware
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
// middleware supporting JSON, urlencoded and multipart requests
app.use(express.bodyParser());
// compression
app.use(express.methodOverride());
app.use(express.static(__dirname));
app.use(app.router);
});
app.configure('development', function(){
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
// get api
app.get('/api/getall', api.getall);
app.get('/api/getreportnumber', api.getreportnumber);
app.get('/api/getdistrictnumber', api.getdistrictnumber);
app.post('/api/setdata', api.setdata);
app.listen(3000, function() {
console.log("Express server started");
})