added basic http server & form input handler (can pipe server stdout into a logfile or we can add a database)

pull/4/head
joates 10 years ago
parent 71f259c429
commit 6ea9f65a0b

@ -23,14 +23,15 @@
<br /><br />
<ul class="nav nav-list">
<form>
<!-- WARNING: This only works for development system (localhost) -->
<form method="GET" action="http://localhost:8000/email">
<fieldset>
<legend>JOIN US</legend>
<label class="text-info">Enter your email..</label>
<input type="text">
<input type="text" name="email">
<span class="help-block">we'll send you info about future events</span>
<label class="checkbox text-info">
<input type="checkbox"> attend Paris2014
<input type="checkbox" name="paris"> Nov 2014 (Paris)
</label>
<button type="submit" class="btn">Send</button>
</fieldset>

@ -23,14 +23,14 @@
<br /><br />
<ul class="nav nav-list">
<form>
<form method="GET" action="http://clevo:8000/email">
<fieldset>
<legend>JOIN US</legend>
<label class="text-info">Enter your email..</label>
<input type="text">
<input type="text" name="email">
<span class="help-block">we'll send you info about future events</span>
<label class="checkbox text-info">
<input type="checkbox"> attend Paris2014
<input type="checkbox" name="paris"> Nov 2014 (Paris)
</label>
<button type="submit" class="btn">Send</button>
</fieldset>

@ -0,0 +1,34 @@
#!/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)
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('server started on port '+ port)
Loading…
Cancel
Save