gombot/bin/static

39 строки
1.1 KiB
JavaScript
Executable File

#!/usr/bin/env node
// gombot static file server!
const fs = require('fs');
const path = require('path');
const url = require('url');
const http = require('http');
const express = require('express');
const nunjucks = require('nunjucks');
const config = require('../etc/config');
var views = require('../lib/views.js');
var app = express();
var server = http.createServer(app);
var static_root = path.join(__dirname, "..", "public");
var download_root = path.join(__dirname, "..", "downloads");
var env = new nunjucks.Environment(new nunjucks.FileSystemLoader(path.join(__dirname, '..', 'views')));
env.express(app);
console.log("static starting up");
app.use(express.logger());
app.use(express.bodyParser());
// set up rendered views
views.setup(app);
// set up static file serving
app.use(express.static(static_root));
app.use('/downloads', express.static(download_root));
var bindTo = config.process.static;
server.listen(bindTo.port, bindTo.host, function() {
console.log("running on http://" + server.address().address + ":" + server.address().port);
});