forked from karan/ZipUp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
67 lines (54 loc) · 2.12 KB
/
Copy pathapp.js
File metadata and controls
67 lines (54 loc) · 2.12 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
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
/*
Module dependencies
*/
var express = require('express'), // the main ssjs framework
path = require('path'), // for path manipulation
mongoose = require('mongoose'),
app = express(); // create an express app
var db = require('./db');
var routes = require('./routes'); // by default, brings in routes/index.js
/*
Configure environments
*/
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
// Add headers
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8888');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
/*
URL routes
*/
app.get('/', function(req, res) {
res.sendfile('index.html');
});
app.get('/addBathroom', function(req, res) {
res.sendfile('addBathroom.html');
}); // Page to add new bathrooms
app.get('/get/bathrooms/', routes.getAll); // get all bathrooms
app.post('/add/bathroom', routes.addBathroom); // add a new bathroom
app.get('/b/:id', routes.getBathroom); // get details about a bathroom
app.post('/add/review/:bid', routes.addReview); // post a new review at a post
app.get('/get/reviews/:bid', routes.getReviews); // get reviews for a bathroom
app.listen(app.get('port'));
console.log('Express server listening on port ' + app.get('port'));