-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (40 loc) · 1.42 KB
/
server.js
File metadata and controls
49 lines (40 loc) · 1.42 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
'use strict';
/*
TODO:
-- Get random list of Gifs, minimize sending same ones a second time
-- Generate Random Death messages
-- Send at 7 am everyday
-- Setting for sending at random times of month
-- Setting for max times per month
-- Add Web Admin Front end
-- Add client front-end to sign up/confirm
-- Provide unsubscribe option
-- Handle unsubscribe message from SMS
-- Install on Heroku
-- Create some random text message to include with gifs
*/
const config = require('./config');
const app = require('express')();
const bodyParser = require('body-parser');
const routes = require('./routes/routes.js');
const recipients = require('./lib/helpers').recipients;
const jsonfile = require('jsonfile')
const file = './recipients.json'
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: false }))
app.use('/', routes)
app.listen(config.port, () => {
console.log(`Death.ly listening on ${config.port}.`);
})
/* Clean up in the event of server exiting/crashing */
process.on('exit', exitHandler.bind(null,{cleanup:true}));
process.on('SIGINT', exitHandler.bind(null, {exit:true}));
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));
function exitHandler(options, err) {
if (options.cleanup) {
console.log(recipients.getRecipients());
jsonfile.writeFileSync(file, recipients.getRecipients());
}
if (err) console.log(err.stack);
if (options.exit) process.exit();
}