Skip to content

Loading…

Express: Link to source on github. #149

Merged
merged 3 commits into from

2 participants

@nrn
Collaborator
nrn commented

Link to the latest commit on github at the bottom of the page on the express server. #148

@WardCunningham WardCunningham merged commit c26c67d into WardCunningham:master
@WardCunningham

How about we embed this git information in an html comment, not in a visible link?

It might take some experimenting to figure out what kind of links are and aren't clickable in show-source. I was waiting to pull this until I had some time to match it in sinatra. But I see there is another commit I don't want to hold up.

@nrn
Collaborator
nrn commented

I probably should have done that git stuff in a branch, I'll take a look for an easy way for the developers to get to a link but not users later today.

@nrn
Collaborator
nrn commented

I took a look at this and didn't see any consistently good way to do it. What is a clickable link depends both on which browser you're using and how you are looking at the source You can even click on a console.log('url as a string') in chrome which is pretty slick, but no such luck in firebug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 2, 2012
  1. @nrn
  2. @nrn

    Express: Refined github link

    nrn committed
Commits on Mar 5, 2012
  1. @nrn
View
7 server/express/lib/cli.coffee
@@ -1,4 +1,5 @@
-# Cli for the Smallest-Federated-Wiki express server
+# **cli.coffee** command line interface for the
+# Smallest-Federated-Wiki express server
path = require 'path'
optimist = require 'optimist'
@@ -62,11 +63,9 @@ argv = optimist
# If h/help is set print the generated help message and exit.
if argv.h
optimist.showHelp()
- process.exit()
-
# If f/farm is set call../lib/farm.coffee with argv object, else call
# ../lib/server.coffee with argv object.
-if argv.test
+else if argv.test
console.log "WARNING: Server started in testing mode, other options ignored"
server({p: 33333, d: path.join(argv.r, 'spec', 'data')})
else if argv.f
View
5 server/express/lib/defaultargs.coffee
@@ -1,5 +1,6 @@
-# **defaultargs.coffee** when called with on the argv object this
-# module will create reasonable defaults for options not supplied.
+# **defaultargs.coffee** when called on the argv object this
+# module will create reasonable defaults for options not supplied,
+# based on what information is provided.
path = require 'path'
module.exports = (argv) ->
View
19 server/express/lib/farm.coffee
@@ -1,4 +1,4 @@
-# **farm.coffee *
+# **farm.coffee**
# The farm module works by putting a bouncy host based proxy
# in front of servers that it creates
@@ -7,22 +7,37 @@ bouncy = require 'bouncy'
server = require '../'
module.exports = exports = (argv) ->
+ # Map incoming hosts to their wiki's port
hosts = {}
+ # Keep an array of servers that are currently active
runningServers = []
+ # Get the next available port.
nextport = do ->
+ # Start port as farm port -1 so it returns the original farm
+ # port the first time it is used.
+ # TODO: Call out to the os to make sure we return an open and valid port.
port = argv.F - 1
-> port += 1
+ # Bouncy watches for incoming requests on the listen port at the bottom,
+ # and passes them to the callback it's called with,
+ # redirecting the requests at the port specified when
+ # the bounce function is called.
bouncy( (req, bounce) ->
+ # Don't do anything for requests without a host header.
unless req.headers?.host
return
+ # If the host starts with "www." treat it the same as if it didn't
if req.headers.host[0..3] is "www."
req.headers.host = req.headers.host[4..]
+ # if we already have a port for this host, forward the request to it.
if hosts[req.headers.host]
bounce(hosts[req.headers.host])
else
hosts[req.headers.host] = nextport()
+ # Create a new options object, copy over the options used to start the
+ # farm, and modify them to make sense for servers spawned from the farm.
newargv = {}
for key, value of argv
newargv[key] = value
@@ -32,6 +47,8 @@ module.exports = exports = (argv) ->
else
path.join(argv.r or path.join(__dirname, '..', '..', '..'), 'data', req.headers.host)
newargv.u = "http://#{req.headers.host}"
+ # Create a new server, add it to the list of servers, and
+ # once it's ready send the request to it.
local = server(newargv)
runningServers.push(local)
local.once "ready", ->
View
36 server/express/lib/page.coffee
@@ -2,14 +2,15 @@
# Module for interacting with pages persisted on the server.
# Everything is stored using json flat files.
-#### Require some stuff, nothing special here. ####
-fs = require('fs')
-path = require('path')
-mkdirp = require('mkdirp')
-random_id = require('./random_id')
-events = require('events')
+#### Requires ####
+fs = require 'fs'
+path = require 'path'
+mkdirp = require 'mkdirp'
+random_id = require './random_id'
+events = require 'events'
-# Export a function that generates a page handler when called options object.
+# Export a function that generates a page handler
+# when called with options object.
module.exports = exports = (argv) ->
#### Private utility methods. ####
@@ -18,7 +19,7 @@ module.exports = exports = (argv) ->
if err then cb(err)
cb(null, JSON.parse(data))
)
-
+
load_parse_copy = (defloc, file, cb) ->
fs.readFile(defloc, (err, data) ->
if err then cb(err)
@@ -32,8 +33,8 @@ module.exports = exports = (argv) ->
# Reads and writes are async, but serially queued to avoid race conditions.
queue = []
- # Main file io function, when called without page it reads, when called with page
- # it writes.
+ # Main file io function, when called without page it reads,
+ # when called with page it writes.
fileio = (file, page, cb) ->
loc = path.join(argv.db, file)
unless page?
@@ -65,8 +66,8 @@ module.exports = exports = (argv) ->
)
)
- # Control variable that tells if the serial queue is currently happening.
- # Set back to 0 when all jobs are complete.
+ # Control variable that tells if the serial queue is currently working.
+ # Set back to false when all jobs are complete.
working = false
# Keep file io working on queued jobs, but don't block the main thread.
@@ -82,6 +83,7 @@ module.exports = exports = (argv) ->
else
itself.stop()
+ #### Public stuff ####
# Make the exported object an instance of EventEmitter
# so other modules can tell if it is working or not.
itself = new events.EventEmitter
@@ -95,16 +97,14 @@ module.exports = exports = (argv) ->
itself.isWorking = ->
working
- # get takes a slug and a callback, it then calls the callback with the page
- # it wanted, or the same named page from default-data, or a 404 status and message
- # and sends it back.
+ # get method takes a slug and a callback, adding them to the queue,
+ # starting serial if it isn't already working.
itself.get = (file, cb) ->
queue.push({file, page: null, cb})
serial(queue.shift()) unless working
-
-
+
# put takes a slugged name, the page as a json object, and a callback.
- # calls cb with an err if anything goes wrong.
+ # adds them to the queue, and starts it unless it is working.
itself.put = (file, page, cb) ->
queue.push({file, page, cb})
serial(queue.shift()) unless working
View
2 server/express/lib/random_id.coffee
@@ -1,4 +1,4 @@
-# ** random_id.coffee **
+# **random_id.coffee**
# Simple random hex generator, takes an optional number of
# chars that defaults to 16 and returns a random id.
View
10 server/express/lib/server.coffee
@@ -15,16 +15,25 @@ fs = require('fs')
path = require('path')
http = require('http')
hbs = require('hbs')
+child_process = require('child_process')
random = require('./random_id')
passportImport = require('passport')
OpenIDstrat = require('passport-openid').Strategy
defargs = require('./defaultargs')
+
# pageFactory can be easily replaced here by requiring your own page handler
# factory, which gets called with the argv object, and then has get and put
# methods that accept the same arguments and callbacks. That would be the
# easiest way to use the Smallest Federated Wiki with a database backend.
pageFactory = require('./page')
+# When server factory is first started attempt to
+# set version to the git sha id of the last commit.
+version = ''
+gitVersion = child_process.exec('git rev-parse HEAD', (err, stdout, stderr) ->
+ version = stdout
+ )
+
# Set export objects for node and coffee to a function that generates a sfw server.
module.exports = exports = (argv) ->
# Create the main application object, app.
@@ -218,6 +227,7 @@ module.exports = exports = (argv) ->
'logout'
else 'login'
else 'claim'
+ sha: version
}
for page, idx in urlPages
if urlLocs[idx] is 'view'
View
3 server/express/views/static.html
@@ -37,6 +37,9 @@
<input data-provider='http://www.livejournal.com/openid/server.bml' title='livejournal' type='button' value='L'>
</span>
{{/authenticated}}
+ <a href="https://github.com/WardCunningham/Smallest-Federated-Wiki/tree/{{sha}}" target='_blank'>
+ View Source on github.
+ </a>
</form>
</footer>
</body>
Something went wrong with that request. Please try again.