-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (60 loc) · 1.48 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
/*- -~- -~- -~- -~- -~- -~- -~- -~- -~- -~- -~- -~- -~- -~- -~- -~- -~- -~- -*/
/*|
/*| Basic Flexible Server for AWS
/*|
/*| A modular server running on connect
/*|
/*| Author: [Reed](https://github.com/reedspool)
/*|
/*| Setup
/*| `npm install connect serve-static body-parser cookie-session compression`
/*|
/*| Run
/*| node app.js
/*|
/*- -~- -*/
var connect = require('connect');
var serveStatic = require('serve-static');
var compression = require('compression');
var cookieSession = require('cookie-session');
var bodyParser = require('body-parser');
var bDevMode = false;
var app;
var development = {
port: 8181
};
var production = {
port: 80
}
app = connect();
// Check mode
if (process.argv[2] && process.argv[2].match("dev"))
{
// If Dev mode requested
bDevMode = true;
}
/**
* Middleware (each is reached on every request)
*/
// gzip/deflate outgoing responses
app.use(compression());
// store session state in browser cookie
app.use(cookieSession(
{
keys: ['secret1', 'secret2']
}));
// parse urlencoded request bodies into req.body
app.use(bodyParser.urlencoded());
/**
* Routes (may not continue)
*/
// Include routes from drawing app
require('./drawing.js')(app);
// If no other route hit, attempt to serve static stuff
app.use(serveStatic(__dirname + '/public'))
// Okay, start'r up!
try {
app.listen(bDevMode ? development.port : production.port);
} catch (e) {
console.error("EACCESS: Try again as super or switch to dev mode.");
}