xonecas.io
818
Du

dustymarkdown / files

dustymarkdown / server.js

1.4 KB
1// author: Sean Caetano Martin (xonecas)
2var builder = require("./lib/build.js");
3//
4builder(true); // compression: true/false
5
6var connect = require('connect'),
7   url = require('url');
8   inspect = require('util').inspect;
9
10var routes = function (app) {
11   // this must be the last route, its an addition to the static provider
12   app.get('*', function (req, res, next) {
13      var pathname = url.parse(req.url).pathname;
14      if (!/\..+$/.test(pathname) && pathname !== '/')
15         req.url += ".html";
16
17      var reqPath = req.url;
18
19      var userAgent = req.headers['user-agent'];
20      if (userAgent && userAgent.indexOf('MSIE') && 
21         reqPath.match(/\.html$/) || reqPath.match(/\.htm$/))
22         res.setHeader('X-UA-Compatible', "IE=Edge,chrome=1");
23
24      // protect .files
25      if (reqPath.match(/(^|\/)\./))
26         res.end("Not allowed");
27
28      next(); // let the static server do the rest
29   });
30}
31
32var oneMonth = 1000 * 60 * 60 * 24 * 30;
33// start the server
34var server = connect.createServer(
35   connect.logger("* :date * :remote-addr * :status * :method * :url * \
36:user-agent"),
37
38   connect.router(routes),
39   connect.static(__dirname+'/static', {maxAge: oneMonth})
40);
41
42server.listen(6661);
43
44// Your server is running :-)
45console.log('Node server is running!');
46
47/*
48process.on('uncaughtException', function (err) {
49   console.log('Caught exception: ' + err);
50});
51*/