litejs
Version:
Single-page application framework
45 lines (34 loc) • 974 B
JavaScript
chdir(__filename.replace(/\/[^\/]*$/, ""))
var litejs = require("litejs")
, app = module.exports = litejs.app({
errors: {
"Error": { code: 500 }
}
})
, log = litejs.log("app")
, logReq = litejs.log("http:req")
function logRequest(req, res, next) {
var url = req.url
res.on("finish", function() {
// var isSSL = req.socket.encrypted
// var isSSL = this instanceof https.Server
// var isSSL = this === httpsServer
logReq(req.ip, req.method, url, res.statusCode, (+new Date() - req.date) + "ms") // res._contentLength
})
next()
}
app
.use(logRequest, app.initRequest, app.readBody)
.post("/errlog", function(req, res, next) {
log("UI ERROR\n" + req.body)
res.sendStatus(204)
})
.get(app.static("../ui"))
if (module === require.main) {
log.info("Starting [%s] on", process.pid,
process.arch, process.platform, JSON.stringify(process.versions, null, 2)
)
log("Config", JSON.stringify(process.config))
app.listen()
}
process.