forked from joemccann/dillinger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
100 lines (82 loc) · 2.84 KB
/
app.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Main Application File for Dillinger.
*/
'use strict'
var config = require('./config')()
, connect = require('connect')
, methodOverride = require('method-override')
, logger = require('morgan')
, favicon = require('serve-favicon')
, compress = require('compression')
, bodyParser = require('body-parser')
, cookieParser = require('cookie-parser')
, cookieSession = require('cookie-session')
, express = require('express')
, routes = require('./routes')
, serveStatic = require('serve-static')
, errorHandler = require('errorhandler')
, path = require('path')
, fs = require('fs')
, app = express()
, core = require('./plugins/core/server.js')
, dropbox = require('./plugins/dropbox/server.js')
, github = require('./plugins/github/server.js')
, googledrive = require('./plugins/googledrive/server.js')
, onedrive = require('./plugins/onedrive/server.js')
, env = process.env.NODE_ENV || 'development';
app.set('port', process.env.PORT || 8080)
app.set('bind-address', process.env.BIND_ADDRESS || 'localhost')
app.set('views', __dirname + '/views')
app.set('view engine', 'ejs')
// May not need to use favicon if using nginx for serving
// static assets. Just comment it out below.
app.use(favicon(path.join(__dirname, 'public/favicon.ico')))
if(env === 'development'){
app.use(logger('dev'))
}
else{
app.use(logger('short'))
}
app.use(compress())
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.use(methodOverride())
app.use(cookieParser('your secret here'))
app.use(cookieSession({
name: 'dillinger-session',
keys: ['open', 'source']
}))
// May not need to use serveStatic if using nginx for serving
// static assets. Just comment it out below.
app.use(serveStatic(__dirname + '/public'))
// Setup local variables to be available in the views.
app.locals.title = config.title || 'Dillinger.'
app.locals.description = config.description || 'Dillinger, the last Markdown Editor, ever.'
if (config.googleWebmasterMeta) {
app.locals.googleWebmasterMeta = config.googleWebmasterMeta
}
if (config.keywords) {
app.locals.keywords = config.keywords
}
if (config.author) {
app.locals.author = config.author
}
app.locals.node_version = process.version.replace('v', '')
app.locals.app_version = require('./package.json').version
app.locals.env = process.env.NODE_ENV
// At startup time so sync is ok.
app.locals.readme = fs.readFileSync(path.resolve(__dirname, './README.md'), 'utf-8')
if ('development' == env) {
app.use(errorHandler())
}
app.get('/', routes.index)
app.get('/not-implemented', routes.not_implemented)
app.use(core)
app.use(dropbox)
app.use(github)
app.use(googledrive)
app.use(onedrive)
app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'))
console.log('\nhttp://' + app.get('bind-address') + ':' + app.get('port') + '\n')
})