2012-11-13 05:17:23 +04:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
// gombot static file server!
|
2012-11-15 04:35:24 +04:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const url = require('url');
|
|
|
|
const http = require('http');
|
|
|
|
const express = require('express');
|
2012-11-13 05:17:23 +04:00
|
|
|
const nunjucks = require('nunjucks');
|
2012-11-15 04:35:24 +04:00
|
|
|
const config = require('../etc/config');
|
2012-11-13 05:17:23 +04:00
|
|
|
|
|
|
|
var views = require('../lib/views.js');
|
|
|
|
|
|
|
|
var app = express();
|
|
|
|
var server = http.createServer(app);
|
|
|
|
|
|
|
|
var static_root = path.join(__dirname, "..", "public");
|
2012-11-21 02:54:52 +04:00
|
|
|
var download_root = path.join(__dirname, "..", "downloads");
|
2012-11-13 05:17:23 +04:00
|
|
|
|
2012-11-15 02:09:02 +04:00
|
|
|
var env = new nunjucks.Environment(new nunjucks.FileSystemLoader(path.join(__dirname, '..', 'views')));
|
2012-11-13 05:17:23 +04:00
|
|
|
env.express(app);
|
|
|
|
|
|
|
|
console.log("static starting up");
|
|
|
|
|
|
|
|
app.use(express.logger());
|
2012-12-04 22:36:29 +04:00
|
|
|
app.use(express.bodyParser());
|
2012-11-13 05:17:23 +04:00
|
|
|
|
|
|
|
// set up rendered views
|
|
|
|
views.setup(app);
|
|
|
|
|
|
|
|
// set up static file serving
|
|
|
|
app.use(express.static(static_root));
|
2012-11-21 02:54:52 +04:00
|
|
|
app.use('/downloads', express.static(download_root));
|
2012-11-13 05:17:23 +04:00
|
|
|
|
2012-11-15 04:35:24 +04:00
|
|
|
var bindTo = config.process.static;
|
2012-11-13 05:17:23 +04:00
|
|
|
server.listen(bindTo.port, bindTo.host, function() {
|
|
|
|
console.log("running on http://" + server.address().address + ":" + server.address().port);
|
|
|
|
});
|