forked from junmer/knowledge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.coffee
53 lines (44 loc) · 1.16 KB
/
server.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
50
51
52
53
express = require 'express'
http = require 'http'
path = require 'path'
stylus = require 'stylus'
nib = require 'nib'
marked = require 'marked'
# build data indexes
indexes = require "#{__dirname}/indexes"
# template compile
compile = (str, path) ->
stylus(str)
.set('filename', path)
.set('compress', true)
.use(nib())
.import('nib')
# create express
app = express()
# init markdown
marked.setOptions
gfm: true
tables: true
breaks: true
app.locals.marked = marked
# all environments
app.set 'port', process.env.PORT or 8888
app.set 'views', "#{__dirname}/views"
app.set 'view engine', 'jade'
app.use express.favicon("#{__dirname}/public/favicon.ico")
app.use express.logger('dev')
app.use express.bodyParser()
app.use express.methodOverride()
app.use app.router
app.use stylus.middleware
src: "#{__dirname}/public"
compile: compile
app.use express.static(path.join(__dirname, 'public'))
app.locals indexes
# development only
if 'development' == app.get('env')
app.use express.errorHandler()
# init routes
require("#{__dirname}/routes/index.coffee")(app)
http.createServer(app).listen app.get('port'), ->
console.log 'Listening on port ' + app.get('port')