/* Config section */
var app, config, console, express, file, fs, http, io, mustache, nodeStatic, render, renderFile, server, socketio;
config = {
version: "0.0.1",
port: 3000
};
/* Require section */
console = require("better-console");
express = require("express");
fs = require("fs");
http = require("http");
mustache = require("mustache");
nodeStatic = require("node-static");
socketio = require("socket.io");
/* App initializing section */
app = express();
server = http.Server(app);
io = socketio(http);
/* Node static initializing section */
file = new nodeStatic.Server('.');
/* Mustache initializing section */
render = mustache.render;
renderFile = function(path, data) {
return render((fs.readSync(fs.openSync(path, "r"), 999999))[0], data);
};
/* Main section */
app.get('/', function(req, res) {
var data;
data = {
vchat: {
version: config.version
},
user: {
name: "Guest"
}
};
res.send(renderFile("templates/index.html", data));
});
app.get("/static/*", function(req, res) {
file.serve(req, res);
});
io.on("connection", function(socket) {
console.log("a user connected");
});
/* Listening section */
server.listen(config.port, function() {
console.clear();
console.info(render('===========================\nServer running on port {{port}}\n===========================', config));
});