Created
May 2, 2012 20:00
-
-
Save marcuswestin/2579841 to your computer and use it in GitHub Desktop.
Dev server springboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/node | |
require('color') | |
var jsCompiler = require('require/server'), | |
express = require('express'), | |
fs = require('fs'), | |
stylus = require('stylus'), | |
curry = require('std/curry'), | |
nib = require('nib') | |
var app = express() | |
app.get('/app', function(req, res) { | |
res.sendfile('src/app/app.html') | |
}) | |
app.get('/stylus/*', function(req, res) { | |
var filename = req.path.replace('/stylus/', '') | |
fs.readFile(filename, function(err, content) { | |
if (err) { return respond(res, err) } | |
stylus(content.toString()) | |
.set('filename', filename) | |
.set('compress', false) | |
.use(nib()) | |
.import('nib') | |
.render(curry(respond, res)) | |
}) | |
}) | |
fs.readdirSync('src').forEach(function(name) { | |
var path = 'src/'+name, | |
stat = fs.statSync(path) | |
if (stat.isFile()) { jsCompiler.addFile(name, path) } | |
else { jsCompiler.addPath(name, path) } | |
}) | |
app.get('/require/*', function(req, res) { | |
jsCompiler.handleRequest(req, res) | |
}) | |
var port = 9000 | |
app.listen(port) | |
console.log('listening'.blue, 'on'.cyan, port.toString().magenta) | |
function respond(res, err, content) { | |
if (err) { | |
res.writeHead(500) | |
res.end((err.stack || err.message || err).toString()) | |
} else { | |
res.writeHead(200) | |
res.end(content) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html><head> | |
<title>App</title> | |
<script src="/require/src/app/app"></script> | |
<link rel="stylesheet" type="text/css" href="/stylus/src/app/app.styl" /> | |
</head><body> | |
</body></html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('lib/jquery') // expects src/lib/jquery.js | |
require('app/foo') // expects src/app/foo.js | |
$(function() { | |
alert("Hello!") | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html | |
height 100%; background linear-gradient(top, white, black); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment