-
Notifications
You must be signed in to change notification settings - Fork 81
/
app.js
134 lines (105 loc) · 4.14 KB
/
app.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var combo = require('combohandler'),
express = require('express'),
exphbs = require('express3-handlebars'),
state = require('express-state'),
config = require('./config'),
helpers = require('./lib/helpers'),
middleware = require('./middleware'),
routes = require('./routes'),
app = express();
// -- Configure ----------------------------------------------------------------
app.set('name', 'Leslie-Eric Wedding');
app.set('env', config.env);
app.set('port', config.port);
app.set('views', config.dirs.views);
app.set('view engine', 'hbs');
app.set('state namespace', 'YUI.Env.LE');
app.enable('strict routing');
app.engine('hbs', exphbs({
defaultLayout: 'main',
extname : '.hbs',
helpers : helpers,
layoutsDir : config.dirs.layouts,
partialsDir : config.dirs.partials
}));
// -- Locals -------------------------------------------------------------------
app.expose(config.yui.config, 'window.YUI_config');
app.locals({
title : 'Leslie & Eric',
appTitle: 'L&E Wedding',
version : config.version,
yui_version: config.yui.version,
nav: [
{id: 'wedding', url: '/wedding/', label: 'Wedding'},
{id: 'logistics', url: '/logistics/', label: 'Logistics'},
{id: 'registry', url: '/registry/', label: 'Registry'},
{id: 'rsvp', url: '/rsvp/', label: 'RSVP'}
],
subnav: {
logistics: [
{id: 'logistics', url: '/logistics/', label: 'Logistics'},
{id: 'hotels', url: '/logistics/hotels/', label: 'Hotels'},
{id: 'outings', url: '/logistics/outings/', label: 'Outings'}
]
},
yui_module: 'le-main',
pictos : config.pictos,
typekit: config.typekit,
isDevelopment: config.isDevelopment,
isProduction : config.isProduction,
min: config.isProduction ? '-min' : ''
});
// -- Middleware ---------------------------------------------------------------
if (config.isDevelopment) {
app.use(express.logger('tiny'));
}
app.use(express.compress());
app.use(express.favicon(config.dirs.pub + '/favicon.ico'));
app.use(express.cookieParser());
app.use(express.cookieSession(config.session));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.csrf());
app.use(middleware.csrfToken);
app.use(middleware.invitation);
app.use(middleware.pjax('bare'));
app.use(middleware.checkDate);
app.use(app.router);
app.use(middleware.slash());
app.use(express.static(config.dirs.pub));
app.use(middleware.notfound);
if (config.isDevelopment) {
app.use(express.errorHandler({
dumpExceptions: true,
showStack : true
}));
} else {
app.use(middleware.error);
}
// -- Routes -------------------------------------------------------------------
app.get('/', routes.render('home'));
app.get('/wedding/', routes.render('wedding'));
app.get('/logistics/', routes.render('logistics'));
app.get('/logistics/hotels/', routes.render('logistics/hotels'));
app.get('/logistics/outings/', routes.render('logistics/outings'));
app.get('/registry/', routes.render('registry'));
app.get( '/rsvp/', routes.rsvp.pub, routes.rsvp.edit);
app.post('/rsvp/', routes.rsvp.resend);
app.get( '/rsvp/brunch/', routes.rsvp.brunch);
app.post('/rsvp/brunch/', routes.rsvp.brunch);
app.get( '/rsvp/brunch/:invitation_key', routes.rsvp.login);
app.get( '/rsvp/:invitation_key', routes.rsvp.login);
app.all( '/invitations/:invitation/*', middleware.auth.ensureInvitation);
app.get( '/invitations/:invitation/', routes.invitations.read);
app.put( '/invitations/:invitation/', routes.invitations.update);
app.get( '/invitations/:invitation/guests', routes.invitations.readGuests);
app.post('/invitations/:invitation/confirm', routes.invitations.confirm);
app.all('/guests/:guest/', middleware.auth.ensureGuest);
app.get('/guests/:guest/', routes.guests.read);
app.put('/guests/:guest/', routes.guests.update);
app.get('/combo/:version', [
combo.combine({rootPath: config.dirs.pub}),
combo.respond
]);
module.exports = app;