// load dependencies var express = require('express'); var bodyParser = require('body-parser'); var path = require('path'); var siofu = require("socketio-file-upload"); var expressHandlebars = require("express-handlebars"); var Handlebars = require('handlebars'); var axios = require('axios'); var config = require('config'); var ua = require('universal-analytics'); var routeHelpers = require('./helpers/routeHelpers.js'); var lbryApi = require('./helpers/lbryApi.js'); var lbryHelpers = require('./helpers/lbryHelpers.js'); var googleAnalyticsId = config.get('AnalyticsConfig.googleId'); var hostedContentPath = config.get('Database.DownloadAddress'); // set port var PORT = 3000; // initialize express app var app = express(); //require our models for syncing var db = require("./models"); // make express look in the public directory for assets (css/js/img) app.use(express.static(__dirname + '/public')); // configure express app app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.use(siofu.router); // configure handlebars & register it with Express app var hbs = expressHandlebars.create({ defaultLayout: 'main', // sets the default layout handlebars: Handlebars, // includes basic handlebars for access to that library helpers: { // define any extra helpers you may need googleAnalytics: function(){ var googleApiKey = config.get('AnalyticsConfig.googleId') return new Handlebars.SafeString(``); } } }); app.engine('handlebars', hbs.engine); app.set('view engine', 'handlebars'); // require express routes require("./routes/api-routes.js")(app, routeHelpers, lbryApi); require("./routes/show-routes.js")(app, routeHelpers, lbryHelpers, ua, googleAnalyticsId); require("./routes/serve-routes.js")(app, routeHelpers, lbryHelpers, ua, googleAnalyticsId); require("./routes/home-routes.js")(app); // require socket.io routes var http = require("./routes/sockets-routes.js")(app, path, siofu, hostedContentPath, ua, googleAnalyticsId); // sync sequelize // wrap the server in socket.io to intercept incoming sockets requests // start server db.sequelize.sync({}) .then(function(){ http.listen(PORT, function() { console.log("Listening on PORT " + PORT); }); });