Created
September 6, 2011 12:43
-
-
Save sfoster/1197446 to your computer and use it in GitHub Desktop.
node jsonp wrapper for static json files
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
var express = require("express"), | |
jsonp = require("connect-jsonp"), | |
path = require('path'), | |
argv = require('optimist').argv; | |
// delegation the way I like it | |
var delegate = function(proto, mixin){ | |
var o = Object.create(proto); | |
if(mixin){ | |
for(var i in mixin) o[i] = mixin[i]; | |
} | |
return o; | |
}; | |
// | |
// set up config for the server, | |
// overriding defaults from argv | |
// | |
var appConfig = delegate({ | |
// default project path is directory above this one | |
// use $0 --projectPath /somewhere/else to configure somewhere else | |
projectPath : path.resolve(__dirname + "/.."), | |
configFile: __dirname + "/my.conf", | |
port: 80 | |
}, argv); | |
var server = module.exports = express.createServer(); | |
server.configure(function () { | |
server.use(jsonp(true)); | |
server.use(express['static'](appConfig.projectPath)); | |
}); | |
if(require.main === module){ | |
server.listen(appConfig.port) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment