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

37 lines
1007 B
JavaScript

#!/usr/bin/env node
var server = require('http').createServer(handler)
, fs = require('fs')
, re = new RegExp('\.js$', 'i')
, port = process.env.PORT || /*80*/ 8000
function handler(req, res) {
// process incoming requests.
if (req.url == '/') req.url = '/index.html'
else if (re.test(req.url))
res.setHeader('Content-Type', 'application/javascript')
if (/^\/email\?/.test(req.url)) {
var params = require('url').parse(req.url, true)
if (params && params.query.email) // @TODO: validate input
console.log('got email:', params.query)
res.statusCode = 302
res.setHeader('Location', '/')
return res.end()
}
// serve static assets
var rs = fs.createReadStream(__dirname +'/html'+ req.url)
rs.pipe(res)
}
process.on('uncaughtException', function (err) {
console.error('Error at:', new Date)
console.error(err.stack)
})
server.listen(port)
console.log('['+ process.pid +'] server started on port '+ port)
console.log('(use ctrl+c to stop server)')