Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

migrate to express 3, switch to ws-rpc, bump to 0.0.4

  • Loading branch information...
commit 3ec6750bbc6f231edea863166bd023b9ff2f962f 1 parent df83d45
@youurayy youurayy authored
View
2  README.md
@@ -1,6 +1,6 @@
# Github Flavored Markdown Server (GFMS)
-### (based on Node.js, Express.js, Jade, Stylus, Socket.io and GFM for JavaScript)
+### (based on Node.js, Express.js, Jade, Stylus, ws-rpc and GFM for JavaScript)
---
I could not find a tool that would allow me to preview Github Flavored Markdown files offline, so I wrote one. (Well it's not completely offline - it loads the Github CSS from Akamai and JQuery from Google's CDN, but you know how to cache them if you need to.)
View
15 gfms.js
@@ -8,15 +8,19 @@ var argv = require('optimist')
.default('h', 'localhost')
.argv;
-var sio = require('socket.io'), io;
var express = require('express');
var stylus = require('stylus');
var nib = require('nib');
-var app = express.createServer();
+var app = express();
+var http = require('http');
+var server = http.createServer(app);
var markdown = //require('github-flavored-markdown').parse;
require('./showdown.js').parse;
var _ = require('underscore');
var fs = require('fs');
+var ews = require('ws');
+var ws = require('ws-rpc').extend(ews);
+var wss = new ws.Server({ server: server });
var request = require('request');
var laeh = require('laeh2').leanStacks(true);
@@ -52,6 +56,7 @@ app.configure(function() {
}));
}
+ app.use(wss.middleware(express));
app.use(express.favicon());
app.use(app.router);
app.use(express.static(pub));
@@ -109,7 +114,7 @@ app.get('*', function(req, res, next) {
fs.watchFile(dir, { interval: 500 }, function(curr, prev) {
if(curr.mtime.getTime() !== prev.mtime.getTime()) {
console.log('file ' + dir + ' has changed');
- io.sockets.json.send({ update: dir, content: markdown(fs.readFileSync(dir, 'utf8')) });
+ wss.message('update', { update: dir, content: markdown(fs.readFileSync(dir, 'utf8')) });
}
});
watched[dir] = true;
@@ -145,9 +150,7 @@ request('http://www.github.com', function(err, res, body) {
if(!styles.length)
throw 'Cannot parse .css links from Github';
- app.listen(argv.p, argv.h);
- io = sio.listen(app);
- io.set('log level', 1);
+ server.listen(argv.p, argv.h);
console.log('GFMS serving ' + process.cwd() + ' at http://' + argv.h + ':' + argv.p + '/ - press CTRL+C to exit.');
});
View
7 package.json
@@ -3,7 +3,7 @@
"name": "gfms",
"description": "Github Flavored Markdown Server",
"keywords": [ "markdown", "server", "local", "reloading" ],
- "version": "0.0.3",
+ "version": "0.0.4",
"homepage": "http://github.com/ypocat/gfms",
"repository": {
"type": "git",
@@ -17,7 +17,7 @@
"gfms": "./bin/gfms"
},
"engines": {
- "node": ">= 0.6.0"
+ "node": "*"
},
"dependencies": {
"express": "*",
@@ -27,7 +27,8 @@
"nib": "*",
"optimist": "*",
"request": "*",
- "socket.io": "*",
+ "ws": "*",
+ "ws-rpc": "*",
"stylus": "*",
"underscore": "*",
"utilz": "*"
View
6 public/gfms.js
@@ -2,8 +2,10 @@ $(function() {
var filename = $('#content').data('filename');
- var socket = io.connect();
- socket.on('message', function(data) {
+ var WebSocketRPC = InitWebSocketRPC(WebSocket);
+ var ws = new WebSocketRPC('ws://' + window.location.host + '/');
+
+ ws.on('update', function(data) {
if(filename === data.update)
$('div.markdown-body').html(data.content);
});
View
2  views/layout.jade
@@ -9,7 +9,7 @@ html
//link(rel='stylesheet', href='https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github2-295a02b2f2bdc835d7af368e96a0579808719484.css')
link(rel='stylesheet', href='/style.css')
script(src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js')
- script(src='/socket.io/socket.io.js')
+ script(src='/ws-rpc-client.min.js')
script(src='/gfms.js')
body
block content
Please sign in to comment.
Something went wrong with that request. Please try again.