forked from joemccann/dillinger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
139 lines (100 loc) · 3.94 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, http = require('http')
, path = require('path')
, fs = require('fs')
var app = express()
app.configure(function(){
app.set('port', process.env.PORT || 80)
app.set('views', __dirname + '/views')
app.set('view engine', 'ejs')
app.use(express.favicon())
app.use(express.logger('dev'))
app.use(express.bodyParser())
app.use(express.methodOverride())
app.use(express.cookieParser('your secret here'))
app.use(express.cookieSession())
app.use(app.router)
app.use(require('stylus').middleware(__dirname + '/public'))
app.use(express.static(path.join(__dirname, 'public')))
var package = require(path.resolve(__dirname, './package.json'))
// Setup local variables to be available in the views.
app.locals.title = "Online Markdown Editor - Dillinger, the Last Markdown Editor ever."
app.locals.description = "Online cloud based HTML5 filled Markdown Editor"
app.locals.node_version = process.version.replace('v', '')
app.locals.app_version = package.version
app.locals.env = process.env.NODE_ENV
app.locals.readme = fs.readFileSync( path.resolve(__dirname, './README.md'), 'utf-8')
// Compress/concat files for deploy env...
// Need to run this locally BEFORE deploying
// to nodejitsu
if(app.locals.env === 'predeploy'){
// Smoosh the things
var smoosh = require('smoosh')
smoosh.make({
"VERSION": app.locals.app_version,
"JSHINT_OPTS": {
"browser": true,
"evil":true,
"boss":true,
"asi": true,
"laxcomma": true,
"expr": true,
"lastsemic": true,
"laxbreak":true,
"regexdash": true,
},
"JAVASCRIPT": {
"DIST_DIR": "./public/js",
"dependencies": [ { "src": "./public/js/bootstrap.js", "jshint": false},
{ "src": "./public/js/ace.js", "jshint": false},
{ "src": "./public/js/mode-markdown.js", "jshint": false},
{ "src": "./public/js/showdown.js", "jshint": false},
{ "src": "./public/js/keymaster.js", "jshint": false}],
"dillinger": [ "./public/js/dillinger.js" ]
},
"CSS": {
"DIST_DIR": "./public/css",
"style": [ "./public/css/style.css" ]
}
})
} // end if production env
})
app.configure('development', function(){
app.use(express.errorHandler())
})
app.get('/', routes.index)
app.get('/not-implemented', routes.not_implemented)
/* Begin Dropbox */
app.get('/oauth/dropbox', routes.oauth_dropbox)
app.get('/unlink/dropbox', routes.unlink_dropbox)
app.get('/import/dropbox', routes.import_dropbox)
app.get('/account/dropbox', routes.account_info_dropbox)
app.post('/fetch/dropbox', routes.fetch_dropbox_file)
app.post('/save/dropbox', routes.save_dropbox)
/* End Dropbox */
/* Begin Github */
app.get('/oauth/github', routes.oauth_github)
app.get('/unlink/github', routes.unlink_github)
app.get('/account/github', routes.account_info_github)
app.post('/import/github/repos', routes.import_github_repos)
app.post('/import/github/branches', routes.import_github_branches)
app.post('/import/github/tree_files', routes.import_tree_files)
app.post('/import/github/file', routes.import_github_file)
app.post('/save/github', routes.save_github)
/* End Github */
/* Dillinger Actions */
// save a markdown file and send header to download it directly as response
app.post('/factory/fetch_markdown', routes.fetch_md)
// Route to handle download of md file
app.get('/files/md/:mdid', routes.download_md)
// Save an html file and send header to download it directly as response
app.post('/factory/fetch_html', routes.fetch_html)
// Route to handle download of html file
app.get('/files/html/:html', routes.download_html)
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'))
})