forked from outmoded/postmile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.js
executable file
·99 lines (60 loc) · 1.96 KB
/
misc.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
/*
* Copyright (c) 2011 Yahoo! Inc. All rights reserved. Copyrights licensed under the New BSD License.
* See LICENSE file included with this code project for license terms.
*/
// Load modules
var Email = require('./email');
// Declare internals
var internals = {
domain: 'sled.com',
scheme: 'https',
feedbackEmail: 'team@sled.com'
};
// Welcome page
exports.welcome = function (req, res, next) {
res.api.redirect = req.api.profile.view;
next();
};
// About page
exports.about = function (req, res, next) {
res.api.view = { template: 'about' };
next();
};
// Developer page
exports.developer = function (req, res, next) {
res.api.view = { template: 'developer', locals: { theme: 'developer' } };
next();
};
// Developer Console
exports.console = function (req, res, next) {
res.api.view = { template: 'console' };
next();
};
// Set I'm with stupid cookie
exports.stupid = function (req, res, next) {
res.api.cookie = {
values: ['imwithstupid=true'],
attributes: ['Path=/']
};
res.api.redirect = '/';
next();
};
// Feedback page
exports.feedback = function (req, res, next) {
if (req.method === 'GET') {
res.api.view = { template: 'feedback' };
next();
}
else {
var feedback = 'From: ' + (req.body.username ? req.body.username : req.body.name + ' <' + req.body.email + '>') + '\n\n' + req.body.message;
Email.send(internals.feedbackEmail, 'Posmile site feedback', feedback);
res.api.view = { template: 'feedback', locals: { env: { message: 'Your feedback has been received!'}} };
next();
}
};
// Client configuration script
exports.config = function (req, res, next) {
res.api.result = 'var postmile = { domain: \'' + internals.domain + '\', scheme: \'' + internals.scheme + '\' };';
res.api.isAPI = true;
next();
};