forked from joemccann/dillinger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
135 lines (86 loc) · 3.74 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
/**
* Module dependencies.
*/
var config = require('./config')();
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 || 8080)
app.set('views', __dirname + '/views')
app.set('view engine', 'ejs')
app.use(express.favicon())
app.use(express.logger('dev'))
app.use(express.compress())
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')))
// 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;
app.locals.node_version = process.version.replace('v', '')
app.locals.app_version = require('./package.json').version
app.locals.env = process.env.NODE_ENV
app.locals.readme = fs.readFileSync( path.resolve(__dirname, './README.md'), 'utf-8')
})
app.configure('development', function(){
app.use(express.errorHandler())
})
app.get('/', routes.index)
app.get('/not-implemented', routes.not_implemented)
/* Begin Dropbox */
app.get('/redirect/dropbox', routes.oauth_dropbox_redirect)
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('/redirect/github', routes.oauth_github_redirect)
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 */
/* Begin Google Drive */
app.get('/redirect/googledrive', routes.oauth_googledrive_redirect);
app.get('/oauth/googledrive', routes.oauth_googledrive);
app.get('/unlink/googledrive', routes.unlink_googledrive);
app.get('/import/googledrive', routes.import_googledrive);
app.get('/fetch/googledrive', routes.fetch_googledrive_file);
app.post('/save/googledrive', routes.save_googledrive);
/* End Google Drive */
/* 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)
app.post('/factory/fetch_html_direct', routes.fetch_html_direct)
// Route to handle download of html file
app.get('/files/html/:html', routes.download_html)
// Save a pdf file and send header to download it directly as response
app.post('/factory/fetch_pdf', routes.fetch_pdf)
// Route to handle download of pdf file
app.get('/files/pdf/:pdf', routes.download_pdf)
/* End Dillinger Actions */
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'))
console.log("\nhttp://localhost:" + app.get('port') + "\n")
})