Created
July 28, 2012 21:37
-
-
Save donabrams/3194901 to your computer and use it in GitHub Desktop.
heroku node web app skeleton with scalable webserver, rss, and websockets
This file contains hidden or 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
| var MONGO_URI = process.env.MONGOLAB_URI || 'mongodb://127.0.0.1:27017/test'; | |
| var PORT = process.env.PORT || 8000; | |
| var url = require('url'); | |
| var REDIS_URI = url.parse(process.env.REDISTOGO_URL || "redis://dev:[email protected]/"); | |
| var express = require('express'); | |
| var sio = require('socket.io'); | |
| var rss = require('rss'); | |
| var RedisStore = require('connect-redis')(express); | |
| var redisAuth = REDIS_URI.auth.split(':'); | |
| var redisStore = new RedisStore({ | |
| host: REDIS_URI.hostname, | |
| port: REDIS_URI.port, | |
| db: redisAuth[0], | |
| pass: redisAuth[1] | |
| }); | |
| var app = express.createServer(); | |
| app.set('views', __dirname); | |
| app.set('view engine', 'jade'); | |
| app.use(express.logger()); | |
| app.use(express.limit('5kb')); | |
| app.use(express.bodyParser()); | |
| app.use(express.cookieParser()); | |
| app.use(express.session({ | |
| secret: process.env.SESSION_KEY || "takeonlywhatyouneed", | |
| store: redisStore})); | |
| app.use(express.csrf()); | |
| app.use(require("stylus").middleware({ | |
| debug: true, | |
| src: __dirname, | |
| dest: __dirname, | |
| compress: true | |
| })); | |
| app.use(function(req,res,next) { | |
| res.locals._csrf = req.session._csrf; | |
| next(); | |
| }); | |
| app.get("/foobar", function(req, res) { | |
| /* what you really do */ | |
| }); | |
| //config the rss feed | |
| var feed = new rss({ | |
| title: 'foo', | |
| description: 'bar', | |
| feed_url: baseUrl + '/rss.xml', | |
| site_url: baseUrl, | |
| image_url: baseUrl + '/logo.png', | |
| author: '' | |
| }); | |
| var xml = feed.xml(); | |
| app.get("/rss.xml", function(req, res) { | |
| res.contentType("rss"); | |
| res.send(xml); | |
| }); | |
| app.use("/", express.static(__dirname)); | |
| //start the express http server | |
| var httpServer = app.listen(PORT, function() { | |
| console.log("Listening on " + PORT); | |
| }); | |
| //start the socketio server | |
| var io = sio.listen(httpServer); | |
| io.set("log level",2); | |
| io.set('transports', ['xhr-polling']); | |
| io.set('polling duration', 10); | |
| //TODO: get redis store working for socketio, not scalable as is here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment