-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
107 lines (93 loc) · 3.76 KB
/
app.js
File metadata and controls
107 lines (93 loc) · 3.76 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
/*jslint nomen:true es5:true */
/**
* Module dependencies.
*/
var express = require('express'),
RedisStore = require('connect-redis')(express),
routes = require('./routes'),
http = require('http'),
path = require('path');
var app = express();
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept, Set-Cookie');
res.header('Access-Control-Expose-Headers','*');
next();
};
app.configure(function () {
app.set('port', process.env.PORT || 3000);
app.configure('development', function () {
app.use(express.errorHandler());
app.locals.pretty = true;
});
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(allowCrossDomain);
app.use(express.cookieParser());
app.use(express.session({
store: new RedisStore(),
key: 'mb_auth',
secret: 'fortesting756498',
cookie: {
domain: 'localhost',
httpOnly: false,
}
}
));
app.use(app.router);
});
app.configure('development', function () {
app.use(express.errorHandler());
});
// // === INDEX
app.get('/', routes.index);
// // === USER ROUTES
app.post('/users', routes.users.addUpdateUser);
//app.post('/users/changepassword', routes.users.changePassword);
app.post('/users/login', routes.users.login); //?username=...&password=...
app.options('/users/login', routes.users.check);
app.get('/users/logout', routes.users.logout);
app.get('/users/details/:ids', routes.users.details);
app.get('/users', routes.users.check);
// // === INGREDIENTS ROUTES
app.get('/fermentables', routes.fermentables.fermentables);
app.get('/fermentables/grains', routes.fermentables.grains);
app.get('/fermentables/grains/:grain', routes.fermentables.grain);
app.get('/fermentables/sugars', routes.fermentables.sugars);
app.get('/fermentables/sugars/:sugar', routes.fermentables.sugar);
app.get('/fermentables/extracts', routes.fermentables.extracts);
app.get('/fermentables/extracts/dryextracts', routes.fermentables.dryExtracts);
app.get('/fermentables/extracts/dryextracts/:dryextract', routes.fermentables.dryExtract);
app.get('/fermentables/extracts/liquidextracts', routes.fermentables.liquidExtracts);
app.get('/fermentables/extracts/liquidextracts/:liquidextract', routes.fermentables.liquidExtract);
app.get('/fermentables/extracts/:extract', routes.fermentables.extract);
app.get('/fermentables/:fermentable', routes.fermentables.fermentable);
app.get('/hops', routes.hops.hops);
app.post('/hops', routes.hops.updateHops);
app.get('/hops/:hop', routes.hops.hop);
app.get('/yeasts', routes.yeasts.yeasts);
app.get('/yeasts/liquidyeasts', routes.yeasts.liquidYeasts);
app.get('/yeasts/liquidyeasts/:liquidyeast', routes.yeasts.liquidYeast);
app.get('/yeasts/dryyeasts', routes.yeasts.dryYeasts);
app.get('/yeasts/dryyeasts/:dryyeast', routes.yeasts.dryYeast);
app.get('/yeasts/:yeast', routes.yeasts.yeast);
app.get('/others', routes.others.others);
app.get('/origins', routes.origins);
app.get('/suppliers', routes.suppliers);
app.get('/beerstyles', routes.beer.beerStyles);
//RECIPE ROUTES
app.post('/recipes', routes.recipe.addRecipe);
app.get('/recipes/:recipe', routes.recipe.getRecipe);
// 404
app.use(function(req,res){
res.writeHead(404, {'Content-Type' : 'application/json'});
res.end('{"error" : "Endpoint not found."}');
});
http.createServer(app).listen(app.get('port'), function () {
console.log("Express server listening on port " + app.get('port'));
});