Skip to content

Commit 060cd7f

Browse files
committed
add the routes asynchronously, so 404 works correctly, #13
1 parent 39c9030 commit 060cd7f

12 files changed

+34
-34
lines changed

src/routes/execute.coffee

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Fs = require 'fs'
44
CONFIG = require '../config'
55
Request = require 'superagent'
66

7-
module.exports = (app, opts) ->
8-
opts or= {}
7+
module.exports = (app, done) ->
98

109
app.swagger '/api/execute',
1110
post:
@@ -59,3 +58,5 @@ module.exports = (app, opts) ->
5958
res.send '@link': executionUri
6059
res.status 201
6160
return res.end()
61+
62+
done()

src/routes/header.coffee

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
module.exports = (app, opts) ->
2-
opts or= {}
1+
module.exports = (app, done) ->
32

43
app.get '/_header', (req, res, next) ->
54
res.render 'header'
5+
6+
done()
7+

src/routes/json-import.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ _postResource = (origDB, resourceEndpoint, callback) ->
6464
return callback err if err
6565
return callback null, _replaceAll(origDB, mapping)
6666

67-
module.exports = (app, opts) ->
68-
69-
opts or= {}
67+
module.exports = (app, done) ->
7068

7169
app.swagger '/api/json-import',
7270
post:
@@ -114,3 +112,5 @@ module.exports = (app, opts) ->
114112
, (err) ->
115113
return next err if err
116114
return res.send JSON.stringify JSON.parse(serializedDB), null, 2
115+
116+
done()

src/routes/ldf.coffee

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1+
module.exports = (app, done) ->
12

2-
module.exports = (app, opts) ->
3-
opts or= {}
4-
5-
app.schemo.handlers.ldf.inject(app, opts)
3+
app.schemo.handlers.ldf.inject(app, done)

src/routes/monitor.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ CONFIG = require '../config'
55

66
log = require('../log')(module)
77

8-
module.exports = (app, opts) ->
9-
opts or= {}
8+
module.exports = (app, done) ->
109

1110
app.swagger '/api/stats',
1211
get:
@@ -82,4 +81,5 @@ module.exports = (app, opts) ->
8281
return res.render 'monitor', { byStatus, statuses, allExecutions }
8382
else
8483
return res.send allExecutions
84+
done()
8585

src/routes/play.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ BodyParser = require 'body-parser'
22

33
log = require('../log')(module)
44

5-
module.exports = (app, opts) ->
6-
opts or= {}
5+
module.exports = (app, done) ->
76

87
app.get '/play/demo1', (req, res, next) ->
98
res.render 'demo-upload'
109

10+
done()

src/routes/restful.coffee

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
module.exports = (app, opts) ->
2-
opts or= {}
1+
module.exports = (app, done) ->
32

43
# restful handlers
5-
app.schemo.handlers.restful.inject(app)
4+
app.schemo.handlers.restful.inject(app, done)
65

src/routes/schemo.coffee

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
module.exports = setupRoutes = (app, opts) ->
2-
opts or= {}
3-
4-
# schema handlers
5-
app.schemo.handlers.schema.inject(app)
1+
module.exports = setupRoutes = (app, done) ->
62

73
# Schema handler for the ontology, i.e. /schema
84
app.get(app.schemo.schemaPrefix,
95
(req, res, next) ->
106
req.jsonld = app.schemo.jsonldTBox()
117
next()
128
app.jsonldMiddleware)
9+
10+
# schema handlers
11+
app.schemo.handlers.schema.inject(app, done)
12+

src/routes/swagger.coffee

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
module.exports = (app, opts) ->
2-
opts or= {}
1+
module.exports = (app, done) ->
32

43
# Swagger interface
54
app.get '/api', (req, res, next) ->
@@ -21,4 +20,4 @@ module.exports = (app, opts) ->
2120
}
2221
]
2322
paths: app.swagger()
24-
}
23+
}, done

src/routes/syntax-highlight.coffee

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ Vim2Html = require 'vim2html'
33

44
log = require('../log')(module)
55

6-
module.exports = (app, opts) ->
7-
opts or= {}
6+
module.exports = (app, done) ->
87

98
app.swagger '/api/syntax-highlight',
109
post:
@@ -64,3 +63,5 @@ module.exports = (app, opts) ->
6463
if err
6564
return next err
6665
res.send highlighted
66+
67+
done()

src/routes/upload.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ Fs = require 'fs'
55
CONFIG = require '../config'
66
Request = require 'superagent'
77

8-
module.exports = (app, opts) ->
8+
module.exports = (app, done) ->
99

10-
opts or= {}
11-
1210
app.swagger '/api/upload',
1311
post:
1412
tags: ['essential']
@@ -92,3 +90,5 @@ module.exports = (app, opts) ->
9290
res.status 201
9391
res.header 'Location', fileModel.uri()
9492
res.send '@link': fileModel.uri()
93+
94+
done()

src/server.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class InfolisWebservice
108108
# Log access
109109
@app.use accessLogger
110110
@app.use accessLoggerDev
111-
controlers = [
111+
controllers = [
112112
'header'
113113
'restful'
114114
'schemo'
@@ -121,9 +121,9 @@ class InfolisWebservice
121121
'syntax-highlight'
122122
'play'
123123
]
124-
Async.eachSeries controlers, (controller, done) =>
124+
Async.eachSeries controllers, (controller, done) =>
125125
log.info "Setting up route #{controller}"
126-
done null, require("./routes/#{controller}")(@app)
126+
require("./routes/#{controller}")(@app, done)
127127
, (err, next) =>
128128
# root route
129129
@app.get '/', (req, res, next) ->

0 commit comments

Comments
 (0)