/* * route.js * * used for handling pathnames in url query */ var util = require('util'); var pnhandler = require('./pnhandler'); /* list of handlers, not a global variable */ var handle = { '/': pnhandler.noop, '/register': pnhandler.register, '/login': pnhandler.login, '/poll': pnhandler.poll, '/upload': pnhandler.upload, '/info' : pnhandler.info, '/hello': pnhandler.hello, '/hellores': pnhandler.hellores }; function route(query, reqdata, res) { if (typeof handle[query.pathname] === 'function' ) { handle[query.pathname](query, reqdata, res); } else { util.log('[route] no handler found for ' + query.pathname); res.writeHead(404, {'Content-Type': 'text/html'}); res.write('\n' + '\n' + '\n' + '\t404 Not found\n' + '\n' + '\n'); res.end(); } } exports.route = route;