forked from Adapp/affiliate_signup_migrated_to_Gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
99 lines (82 loc) · 2.72 KB
/
server.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
var express = require('express'),
http = require('http'),
path = require('path'),
zipper = require('./zipBuilder'),
commander = require('commander'),
expressWinston = require('express-winston'),
winston = require('winston'),
fs = require('fs'),
q = require('q');
var app = module.exports = express();
commander
.version('0.1.0')
.option('-c, --config [path]', 'Absolute path to your config file.')
.option('-p, --port [port]', 'The port to run the application on.')
.parse(process.argv);
var waitForConfig = new q.defer();
if (!commander.config) {
app.set('port', commander.port || 3000);
waitForConfig.resolve();
} else{
fs.readFile(commander.config, function(err, data) {
if (err) {
console.error('There was an error reading from ' + command.config + ' ', err);
process.exit(1);
}
data = JSON.parse(data);
app.set('port', commander.port || data.port || 3000);
app.set('logLocation', data.logLocation);
app.set('errorLogLocation', data.errorLogLocation);
app.set('maxLogSize', data.maxLogSize);
app.set('maxLogFiles', data.maxLogFiles);
waitForConfig.resolve();
});
}
waitForConfig.promise.then(function() {
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.bodyParser());
app.use(express.methodOverride());
if (app.get('logLocation')) {
app.use(expressWinston.logger({
'transports': [
new winston.transports.File({
'filename' : app.get('logLocation'),
'maxsize' : app.get('maxLogSize'),
'maxFiles' : app.get('maxLogFiles')
})
]
}));
}
app.use(app.router);
// Error log needs to come after the router since that's the most likely place for errors to occur.
if (app.get('errorLogLocation')) {
app.use(expressWinston.errorLogger({
'transports': [
new winston.transports.File({
'filename' : app.get('errorLogLocation'),
'maxsize' : app.get('maxLogSize'),
'maxFiles' : app.get('maxLogFiles')
})
]
}));
}
app.use(express.static(path.join(__dirname, 'assets')));
});
app.get('/', function(req, res) {
res.render('index');
});
app.post('/compile', function(req, res) {
zipper(req.body, function(archive) {
res.setHeader('Content-type', 'application/octet-stream');
res.setHeader('Content-disposition', 'attachment; filename=custom_signup.zip');
res.send(archive.toBuffer());
res.end();
});
});
http.createServer(app).listen(app.get('port'), function() {
console.log("Express server listening on port " + app.get('port'));
});
});