Skip to content
This repository has been archived by the owner on Feb 14, 2018. It is now read-only.

Commit

Permalink
Express: npm test command and oops error page.
Browse files Browse the repository at this point in the history
  • Loading branch information
nrn committed Jan 29, 2012
1 parent 4718df2 commit f616b9b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
4 changes: 3 additions & 1 deletion server/express/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ node-canvas. For now, please see node-canvas to install.
## Newest Docs
Command line options can be seen by running:

bin/server.js -h
bin/server.js -h

The most up to date node server specific documentation is in the source
code, in a way that is best viewed when processed with
Expand Down Expand Up @@ -50,6 +50,8 @@ but for now both of these should be supported.

## Running specs

* The unit tests can be run with:
npm test
* Make sure you have Ruby 1.9.x installed, as well as the 'bundler' gem
* Run `bundle install` in the root
* Start the Express server at port 33333, with the data directory
Expand Down
26 changes: 17 additions & 9 deletions server/express/lib/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = exports = (argv) ->
next()
else if req.isAuthenticated() and req.user.id is owner
next()
else res.send('Access forbidden', 403)
else res.send('Access Forbidden', 403)

# Simplest possible way to serialize and deserialize a user.
passport.serializeUser( (user, done) ->
Expand Down Expand Up @@ -95,6 +95,13 @@ module.exports = exports = (argv) ->
)
)))

openIDErr = (err, req, res, next) ->
console.log err
if err.message[0..5] is 'OpenID'
res.render('oops.html', {status: 401, msg:err.message})
else
next(err)

#### Express configuration
app = express.createServer()
# Set up all the standard express server options,
Expand All @@ -113,6 +120,7 @@ module.exports = exports = (argv) ->
app.use(passport.session())
app.use(app.router)
app.use(express.static(argv.c))
app.use(openIDErr)
)

##### Set up standard environments.
Expand Down Expand Up @@ -145,8 +153,8 @@ module.exports = exports = (argv) ->
"http://#{req.params[0]}"
)

app.redirect('notyourwiki', (req, res) ->
'/notyourwiki'
app.redirect('oops', (req, res) ->
'/oops'
)

##### Get routes
Expand Down Expand Up @@ -321,7 +329,7 @@ module.exports = exports = (argv) ->
# Currently throws an error to next(err) when id is blank.
# TODO: Handle that error more gracefully.
app.post('/login',
passport.authenticate('openid', { failureRedirect: 'notyourwiki'}),
passport.authenticate('openid', { failureRedirect: 'oops'}),
(req, res) ->
res.redirect('index')
)
Expand All @@ -340,15 +348,15 @@ module.exports = exports = (argv) ->

# Route that the openID provider redirects user to after login.
app.get('/login/openid/complete',
passport.authenticate('openid', { failureRedirect: 'notyourwiki'}),
passport.authenticate('openid', { failureRedirect: 'oops'}),
(req, res) ->
res.redirect('index')
)

# Simple Access forbidden message when someone tries to log into a wiki
# they do not own.
app.get('/notyourwiki', (req, res) ->
res.send('This is not your wiki!', 403)
app.get('/oops', (req, res) ->
res.render('oops.html', {status: 403, msg:'This is not your wiki!'})
)

# Traditional request to / redirects to index :)
Expand All @@ -357,9 +365,9 @@ module.exports = exports = (argv) ->
)

#### Starting the server.
setOwner null, ->
setOwner( null, ->
app.listen(argv.p, argv.o if argv.o)
app.emit "ready"
console.log("Smallest Federated Wiki server listening on #{app.address().port} in mode: #{app.settings.env}")

)
app
3 changes: 3 additions & 0 deletions server/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"hbs": ">= 0.0.1",
"bouncy": ">= 0.0.1"
},
"scripts": {
"test": "./node_modules/mocha/bin/mocha"
},
"devDependencies": {
"docco": "*",
"mocha": "*",
Expand Down
13 changes: 13 additions & 0 deletions server/express/views/oops.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="font-family: &quot;Helvetica Neue&quot;, helvetica, Verdana, Arial, Sans;">
<center>
<img src="/images/oops.jpg">
<h1 style="width:400; color:#f10">
{{msg}}
</h1>
</center>
</body>
</html>
13 changes: 7 additions & 6 deletions server/express/views/static.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta content='width=device-width, height=device-height, initial-scale=1.0, user-scalable=no' name='viewport'>
<link href='/favicon.png' rel='icon' type='image/png'>
<link href='/style.css' rel='stylesheet' type='text/css'>
<script src='/js/jquery-1.6.2.min.js' type='text/javascript'></script>
<script src='/js/jquery-1.7.1.min.js' type='text/javascript'></script>
<script src='/js/jquery-ui-1.8.16.custom.min.js' type='text/javascript'></script>
<link href='/js/jquery-ui-1.8.16.custom.css' rel='stylesheet' type='text/css'>
<script src='/js/history.min.js' type='text/javascript'></script>
Expand All @@ -24,20 +24,21 @@
<footer class={{status}}>
{{#authenticated}}
<form action='/logout' method='POST'>
<input type='submit' value={{status}}>
{{/authenticated}}
{{^authenticated}}
<form action='/login' method='POST'>
OpenID:
<input name='identifier' type='text'>
<input type='submit' value={{status}}>
or use:
<span class='provider'>
<input type='button' title='google' value='G' data-provider='https://www.google.com/accounts/o8/id'>
<input type='button' title='yahoo' value='Y' data-provider='https://me.yahoo.com'>
<input type='button' title='aol' value='A' data-provider='https://www.aol.com'>
<input type='button' title='livejournal' value='L' data-provider='http://www.livejournal.com/openid/server.bml'>
<input data-provider='https://www.google.com/accounts/o8/id' title='google' type='button' value='G'>
<input data-provider='https://me.yahoo.com' title='yahoo' type='button' value='Y'>
<input data-provider='https://www.aol.com' title='aol' type='button' value='A'>
<input data-provider='http://www.livejournal.com/openid/server.bml' title='livejournal' type='button' value='L'>
</span>
{{/authenticated}}
<input type='submit' value={{status}}>
</form>
</footer>
</body>
Expand Down

0 comments on commit f616b9b

Please sign in to comment.