-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroutes.coffee
34 lines (27 loc) · 1.13 KB
/
routes.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
util = require('util')
_ = require('underscore')
# Module which encapsulates all the application routes
module.exports = (app, controllers, repository) ->
# app.get "/", (req, res) ->
# action = req.params['action'] || 'index'
# controllers.main[action](req, res)
app.get "/:action?", [authorize], (req, res) ->
action = req.params['action'] || 'index'
controllers.main[action](req, res)
app.get "/:controller/:action?", [authorize], (req, res) ->
controllers[req.params['controller']][req.params['action']](req, res)
app.get "/:controller/:action/:id", [authorize], (req, res) ->
req.id = req.params['id']
controllers[req.params['controller']][req.params['action']](req, res)
app.post "/login", controllers.main.login
# Any request that falls all the way through is considered a 404
app.use (req, res) ->
res.render "404", status: 404, title: "Page not found"
# Authorization middleware function
authorize = (req, res, next) ->
#TODO: Perform any custom authorization logic
authorized = true
if authorized is false
res.render "403", status: 403, title: "Unauthorized access"
else
next()