spee.ch/server.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

// load dependencies
var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');
2017-06-01 04:48:09 +02:00
var siofu = require("socketio-file-upload");
2017-06-10 01:46:57 +02:00
var expressHandlebars = require("express-handlebars");
2017-05-25 07:50:02 +02:00
// set port
2017-05-24 23:22:56 +02:00
var PORT = 3000;
2017-05-25 07:50:02 +02:00
// initialize express app
var app = express();
2017-05-25 07:50:02 +02:00
// make express look in the public directory for assets (css/js/img)
app.use(express.static(__dirname + '/public'));
2017-05-25 07:50:02 +02:00
// configure express app
2017-06-10 01:46:57 +02:00
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
2017-06-01 04:48:09 +02:00
app.use(siofu.router);
2017-05-25 07:50:02 +02:00
2017-06-10 01:46:57 +02:00
// configure handlebars
app.engine('handlebars', expressHandlebars({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
2017-05-25 07:50:02 +02:00
// require express routes
require("./routes/api-routes.js")(app);
require("./routes/html-routes.js")(app);
2017-05-25 07:50:02 +02:00
2017-06-10 01:46:57 +02:00
// wrap the server in socket.io to intercept incoming sockets requests
2017-05-25 07:50:02 +02:00
var http = require("./routes/sockets-routes.js")(app);
// start server
2017-05-25 07:50:02 +02:00
http.listen(PORT, function() {
console.log("Listening on PORT " + PORT);
});