-
-
Save mdedetrich/e6c5141771eae4630fb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.env.TZ = 'UTC' | |
http = require 'http' | |
ss = require 'socketstream' | |
express = require 'express' | |
config = require './config.coffee' | |
db = require './server/mongodb/models/models' | |
require './logger' | |
winston = require 'winston' | |
app = express() | |
ss.session.store.use('redis', | |
host: config.get('redisHost') | |
port: config.get('redisPort') | |
pass: config.get('redisPassword') | |
db: config.get('redisDatabase') | |
) | |
ss.ws.transport.use(require('ss-engine.io'),client:{host:'localhost', port:config.get('port') || 8080}); | |
if config.get('authUsername') | |
authorize = (username,password)-> | |
config.get('authUsername') == username and config.get('authPassword') == password | |
app.use(express.basicAuth(authorize)) | |
if config.get('redirectToWWW') | |
app.use((req,res,next)-> | |
if !(req.headers.host.match(/^www/)) | |
res.redirect('http://www.' + req.headers.host+ req.url) | |
else | |
next() | |
) | |
if config.get('forceHTTPS') | |
app.use((req, res, next)-> | |
schema = req.headers["x-forwarded-proto"] | |
if (schema == "https") | |
next() | |
else | |
res.redirect("https://" + req.headers.host + req.url) | |
) | |
ss.client.define('main', | |
view: 'app.jade' | |
css: ['libs/fonts.css','libs/jquery-ui-1.9.0.custom.css','libs/fullcalendar.css','common.styl'] | |
code: ['libs/console.fallback.js','system','libs/jquery.min.js','libs/backbone.js','libs/jquery.imgpreload.js','libs/jquery.timezone-picker.js','libs/jquery.ui.js','libs/fullcalendar.js','libs/jquery.fileupload.js','libs/jquery.fileupload-ui.js','libs/jquery.textPreserve.coffee','libs/jquery.dropdown.coffee','libs/detect_timezone.js','libs/jquery.jstorage.js','app'] | |
tmpl: '*' | |
) | |
ss.client.define('upgrade', | |
view: 'upgrade.jade' | |
css: ['common.styl'] | |
code: [''] | |
tmpl: '*' | |
) | |
ss.client.define('signup', | |
view: 'signup.jade' | |
css: ['common.styl','libs/fonts.css','libs/jquery-ui-1.9.0.custom.css'] | |
code: ['system','libs/jquery.min.js','signup','libs/jquery.ui.js'] | |
tmpl: '*' | |
) | |
app.use(express.bodyParser()) | |
require('./server/routes/facebookAuth')(app) | |
require('./server/routes/imagePool')(app) | |
app.get('/', (req,res)-> | |
res.serveClient('main') | |
) | |
ss.client.formatters.add(require('ss-stylus')) | |
ss.client.formatters.add(require('ss-jade')) | |
ss.client.formatters.add(require('ss-coffee')) | |
ss.client.templateEngine.use(require('ss-clientjade')) | |
if (process.env.env == 'production') then ss.client.packAssets() | |
if config.get('cdn') | |
ss.client.packAssets( | |
keepOldFiles:true | |
cdn: | |
js: (file) -> (config.get('cdn') + '/' + file.path.replace(/^.*[\\\/]/, '')) | |
css: (file) -> (config.get('cdn') + '/' + file.path.replace(/^.*[\\\/]/, '')) | |
html: (file) -> (config.get('cdn') + '/' + file.path.replace(/^.*[\\\/]/, '')) | |
) | |
server = app.listen(config.get('port') || 8080) | |
ss.start(server) | |
app.stack = ss.http.middleware.stack.concat(app.stack) | |
winston.info('blublocks server started') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment