-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.coffee
49 lines (43 loc) · 1.56 KB
/
app.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
###
Module dependencies.
###
express = require("express")
http = require("http")
fs = require("fs")
path = require("path")
_ = require("underscore")
config = require("config")
# Create the app
app = express()
app.configure ->
app.set "port", process.env.PORT or 3000
app.set "views", __dirname + "/views"
app.set "view engine", "jade"
app.use express.favicon()
app.use express.logger("dev")
app.use express.bodyParser()
app.use express.methodOverride()
app.use app.router
app.use require("less-middleware")(src: __dirname + "/public")
app.use express.static(path.join(__dirname, "public"))
# Custom local functions
app.locals
getThumbnail: (prez, w=680, h=480)->
host = process.env.HOST or config.host
prez = host + "/" + prez
key = process.env.BROWSHOT_KEY or config.browshot_key
provider = "https://api.browshot.com/api/v1/simple"
cache = 60*60*24*60 # 60 days cache
return "#{provider}?url=#{prez}&width=#{w}&height=#{h}&key=#{key}&cache=#{cache}"
# Error handler in development mode
app.configure "development", -> app.use express.errorHandler()
# Homepage endpoint
app.get "/", (req, res) ->
prezs = fs.readdirSync(path.join(__dirname, "views", "prez") )
prezs = _.map prezs, (p)-> p.split(".jade")[0]
# Load the home
res.render "home", prezs: prezs
# Presentation endpoint
app.get "/:controller", (req, res) -> res.render "prez/" + req.params.controller
http.createServer(app).listen app.get("port"), ->
console.log "Express server listening on port " + app.get("port")