forked from ggoodman/stsh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.coffee
48 lines (33 loc) · 1.38 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
coffee = require("coffee-script")
express = require("express")
gzippo = require("gzippo")
assets = require("connect-assets")
app = module.exports = express.createServer()
app.use assets()
app.use gzippo.staticGzip("#{__dirname}/public")
app.use gzippo.compress()
app.use express.static("#{__dirname}/public")
app.use "/api/v1", require("./servers/api/v1")
app.use "/raw", require("./servers/plunks")
app.configure ->
app.set "views", "#{__dirname}/views"
app.set "view engine", "jade"
app.set "view options", layout: false
app.use express.logger()
app.use express.errorHandler({ dumpExceptions: true, showStack: true })
app.get "/", (req, res) ->
res.render("index", page: "/")
app.get "/documentation", (req, res) ->
res.render("documentation", page: "/documentation")
app.get "/about", (req, res) ->
res.render("about", page: "/about")
app.get /^\/([a-zA-Z0-9]{6})\/(.*)$/, (req, res) ->
res.local "raw_url", "/raw" + req.url
res.local "plunk_id", req.params[0]
res.render "preview"
app.get /^\/([a-zA-Z0-9]{6})$/, (req, res) -> res.redirect("/#{req.params[0]}/", 301)
app.get /^\/edit(?:\/([a-zA-Z0-9]{6})\/?$)?/, (req, res) ->
res.render("editor", page: "/edit", views: req.param("views", "sidebar editor preview").split(/[ \.,]/).join(" "))
if require.main == module
app.listen process.env.PORT || 8080
console.log "Listening on port %d", process.env.PORT || 8080