forked from findthemasks/findthemasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplicationRoutes.js
More file actions
176 lines (154 loc) · 6.32 KB
/
applicationRoutes.js
File metadata and controls
176 lines (154 loc) · 6.32 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Routes that are mounted under country codes or other paths.
const express = require('express');
const formatFbLocale = require('./utils/formatFbLocale');
const getDonationFormUrl = require('./viewHelpers/getDonationFormUrl.js');
const localizePartialPath = require('./viewHelpers/localizePartialPath');
const getLocalContactEmail = require('./viewHelpers/getLocalContactEmail');
const herokuVersion = process.env.HEROKU_RELEASE_VERSION;
const router = express.Router();
router.get(['/', '/index.html'], (req, res) => {
const isMaker = res.locals.dataset === 'makers';
res.render('index', {
version: herokuVersion,
ogLocale: formatFbLocale(res.locals.locale),
ogTitle: isMaker ? res.locals.banana.i18n('ftm-makers-og-title') : res.locals.banana.i18n('ftm-index-og-title'),
ogUrl: `http://${req.hostname}${req.originalUrl}`,
ogDescription: isMaker ? res.locals.banana.i18n('ftm-makers-og-description') : res.locals.banana.i18n('ftm-index-og-description'),
googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY,
localizeContactInfo: localizePartialPath('contact_info', res.locals.countryCode),
recaptchaSiteKey: process.env.RECAPTCHA_SITE_KEY,
});
});
router.get('/faq', (req, res) => {
res.render('faq', {
version: herokuVersion,
layout: 'static',
ogTitle: res.locals.banana.i18n('ftm-index-og-title'),
ogUrl: `http://${req.hostname}${req.originalUrl}`,
ogDescription: res.locals.banana.i18n('ftm-default-og-description'),
largeDonationSitesPartialPath: localizePartialPath('large_donation_sites', res.locals.countryCode),
maskMatchPartialPath: localizePartialPath('mask_match', res.locals.countryCode),
localContactEmail: getLocalContactEmail(res.locals.countryCode),
});
});
router.get(['/give', '/give.html'], (req, res) => {
res.render('give', {
version: herokuVersion,
layout: 'give',
ogLocale: formatFbLocale(res.locals.locale),
ogTitle: res.locals.banana.i18n('ftm-give-og-title'),
ogUrl: `http://${req.hostname}${req.originalUrl}`,
ogDescription: res.locals.banana.i18n('ftm-default-og-description'),
googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY,
recaptchaSiteKey: process.env.RECAPTCHA_SITE_KEY,
});
});
router.get(['/embed'], (req, res) => {
const isMaker = res.locals.dataset === 'makers';
res.render('give', {
version: herokuVersion,
layout: 'give',
ogLocale: formatFbLocale(res.locals.locale),
ogTitle: isMaker ? '#findthemasks | makers embed' : res.locals.banana.i18n('ftm-give-og-title'),
ogUrl: `http://${req.hostname}${req.originalUrl}`,
ogDescription: res.locals.banana.i18n('ftm-default-og-description'),
googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY,
recaptchaSiteKey: process.env.RECAPTCHA_SITE_KEY,
});
});
router.get('/privacy-policy', (req, res) => {
res.render('privacy-policy', {
version: herokuVersion,
layout: 'static',
ogLocale: formatFbLocale(res.locals.locale),
ogTitle: res.locals.banana.i18n('ftm-privacy-policy-og-title'),
ogUrl: `http://${req.hostname}${req.originalUrl}`,
ogDescription: res.locals.banana.i18n('ftm-privacy-policy-og-description'),
});
});
router.get(['/special-projects/la-makers'], (req, res) => {
res.render('special-projects/la-makers', {
version: herokuVersion,
ogLocale: formatFbLocale(res.locals.locale),
ogTitle: 'Los Angeles Makers',
ogUrl: `http://${req.hostname}${req.originalUrl}`,
ogDescription: 'Map of Vetter Makers for the city of Los Angeles',
googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY,
localizeContactInfo: localizePartialPath('contact_info', res.locals.countryCode),
});
});
router.get(['/request', '/request.html'], (req, res) => {
res.render('request', {
layout: false,
version: herokuVersion,
});
});
router.get(['/stats', '/stats.html'], (req, res) => {
res.render('stats', {
layout: false,
version: herokuVersion,
});
});
router.get('/volunteer', (req, res) => {
res.render('volunteer', {
layout: 'static',
ogTitle: res.locals.banana.i18n('ftm-index-og-title'),
ogUrl: `http://${req.hostname}${req.originalUrl}`,
ogDescription: res.locals.banana.i18n('ftm-default-og-description'),
version: herokuVersion,
localContactEmail: getLocalContactEmail(res.locals.countryCode),
});
});
router.get('/blog/2020-04-21-data-insights', (req, res) => {
res.render('blog/2020_04_21_data_insights', {
layout: 'static',
title: 'Insights from FindTheMasks-US Data',
ogTitle: 'Insights from FindTheMasks-US Data',
ogUrl: `http://${req.hostname}${req.originalUrl}`,
ogDescription: res.locals.banana.i18n('ftm-default-og-description'),
});
});
router.get(['/whoweare', '/whoweare.html'], (req, res) => {
res.render('whoweare', {
layout: 'static',
ogLocale: formatFbLocale(res.locals.locale),
ogTitle: res.locals.banana.i18n('ftm-about-us-og-title'),
ogUrl: `http://${req.hostname}${req.originalUrl}`,
ogDescription: res.locals.banana.i18n('ftm-default-og-description'),
version: herokuVersion,
regionalSpotlightPartialPath: localizePartialPath('regional_spotlight', res.locals.countryCode),
});
});
router.get('/partners', (req, res) => {
res.render('partners', {
layout: 'static',
ogLocale: formatFbLocale(res.locals.locale),
ogTitle: res.locals.banana.i18n('ftm-partners-og-title'),
ogUrl: `http://${req.hostname}${req.originalUrl}`,
ogDescription: res.locals.banana.i18n('ftm-default-og-description'),
version: herokuVersion,
});
});
router.get(['/404', '/404.html'], (req, res) => {
res.render('404', { layout: false });
});
router.get('/donation-form', (req, res) => {
res.redirect(getDonationFormUrl(res.locals.countryCode, res.locals.locale));
});
router.get('/maker-form', (req, res) => {
res.redirect('https://airtable.com/shruH5B27UP3PqKgg');
});
// Recursively handle routes for makers overriding the dataset so the main
// map functionality can be run in a different "mode" so to speak.
router.use('/makers', (req, res, next) => {
const remainingUrl = req.originalUrl.substr(req.baseUrl.length);
if (remainingUrl && !remainingUrl.match(/\/(embed(\/)?)?/)) {
console.log('redirecting');
res.status(404).redirect('/');
return;
}
// Override the dataset. Expect countryCode to be set at the top-level routing.
res.locals.dataset = 'makers';
router(req, res, next);
});
module.exports = router;