forked from prontoeats/pronto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-config.js
48 lines (40 loc) · 1.82 KB
/
app-config.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
var express = require('express');
var dbConnect = require('./db/db-config.js');
var userHandler = require('./server/userHandler.js');
var busHandler = require('./server/busHandler.js');
var authen = require('./server/authenHelpers.js');
var app = express();
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
app.configure(function() {
app.use(express.bodyParser());
app.use(allowCrossDomain);
app.use(express.static(__dirname + '/public'));
});
// public routes
app.post('/login/user', userHandler.login);
app.post('/login/business', busHandler.login);
app.post('/signup/business', busHandler.signup);
// private user routes
app.get('/requests', authen.checkToken, userHandler.sendRequestInfo);
app.post('/token', authen.registerPushToken);
app.post('/validate', authen.checkToken, authen.isValidated);
app.post('/request', authen.checkToken, userHandler.request);
app.post('/requests/accept', authen.checkToken, userHandler.acceptOffer);
app.post('/requests/reject', authen.checkToken, userHandler.rejectOffer);
// private business routes
app.get('/business/requests', authen.checkToken, busHandler.showPending);
app.get('/business/offered', authen.checkToken, busHandler.showOffered);
app.get('/business/accepted', authen.checkToken, busHandler.showAccepted);
app.post('/business/token', authen.registerPushToken);
app.post('/business/validate', authen.checkToken, authen.isValidated);
app.post('/business/requests/accept', authen.checkToken, busHandler.acceptRequests);
app.post('/business/requests/decline', authen.checkToken, busHandler.declineRequests);
app.all('*', function (req, res) {
res.send(404, 'bad route');
});
module.exports = app;