1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Website/server.js

44 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
var fs = require('fs')
, http = require('http')
, stack = require('stack')
, route = require('tiny-route')
, assets = require('ecstatic')
, config = require('./config')
, db = require('level')(config.db_path, config.db_opts)
, port = process.env.PORT || config.port
// create the level db folder if it does not exists
if(!fs.existsSync(config.db_path)){
fs.mkdirSync(config.db_path, 0766, function(err){
if(err){
console.log(err);
}
});
}
stack.errorHandler = function error(req, res, err) {
res.statusCode = 302
res.setHeader('Location', '/')
res.end()
}
var app = stack(
route('/email', require('./src/email-submit')(db))
, route('/confirm', require('./src/email-confirm')(db))
, assets({ root: __dirname +'/html', handleError: false })
)
process.on('uncaughtException', function (err) {
console.error('Error at:', new Date)
console.error(err.stack)
})
http.createServer(app).listen(port, function() {
console.log('[PID='+ process.pid +'] server started on port '+ port)
console.log('(use Ctrl+c to stop the server)')
})