Skip to content

Instantly share code, notes, and snippets.

@medikoo
Created August 10, 2012 08:51
Show Gist options
  • Save medikoo/3312684 to your computer and use it in GitHub Desktop.
Save medikoo/3312684 to your computer and use it in GitHub Desktop.
Static server + Webmake
'use strict';
var createServer = require('http').createServer
, staticServer = require('node-static').Server
, webmake = require('webmake')
, rootPath = '/Users/foobar/Projects/my-project'
, publicPath = rootPath + '/public'
, jsProgramPath = rootPath + '/lib/public/main.js';
staticServer = new staticServer(publicPath);
createServer(function (req, res) {
req.addListener('end', function () {
if (req.url === '/j/main.js') {
res.writeHead(200, { 'Content-Type':
'application/javascript; charset=utf-8',
'Cache-Control': 'no-cache' });
// console.log('start webmake', root + '/lib/public/main.js');
webmake(jsProgramPath, function (err, content) {
if (err) {
throw err;
}
res.end(content);
});
} else {
staticServer.serve(req, res);
}
});
}).listen(8100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment