This repository has been archived by the owner on Mar 12, 2018. It is now read-only.
forked from cauld/docpad-plugin-dce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (60 loc) · 2.36 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
/**
* DocPad Collections Editor
* Copyright Manifold 2013+. All rights reserved.
* Author Chad Auld (chadauld@gmail.com)
* Licensed under the BSD License.
* https://github.com/cauld/docpad-collections-editor
*/
var server,
express = require('express'),
http = require('http'),
app = express(),
path = require('path'),
dceConfig = require('../../dce-config'),
routes = require('./routes'),
addRoutes = require('./routes/add'),
editRoutes = require('./routes/edit'),
serviceRoutes = require('./routes/service');
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
if (dceConfig.useHttpAuth === true) {
if (process.env.DCE_AUTH_USER && process.env.DCE_AUTH_PASSWORD) {
app.use(express.basicAuth(process.env.DCE_AUTH_USER, process.env.DCE_AUTH_PASSWORD));
} else {
console.log("Warning: DCE http auth was requested, but one or more ENV variables are missing! Not enabled.");
}
}
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
server = http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
// Add DocPad to our Application
var docpadInstanceConfiguration = {
// Give it our express application and http server
serverExpress: app,
serverHttp: server,
// Tell it not to load the standard middlewares (as we handled that above)
middlewareStandard: false,
rootPath: path.resolve('../../')
};
GLOBAL.docpadInstance = require('docpad').createInstance(docpadInstanceConfiguration, function(err){
if (err) return console.log(err.stack);
// Tell DocPad to perform a generation, extend our server with its routes, and watch for changes
docpad.action('generate server watch', function(err){
if (err) return console.log(err.stack);
});
});
app.get('/', routes.index);
app.post('/', routes.indexFromSave);
app.get('/add', addRoutes.index);
app.post('/add/save', addRoutes.saveNew);
app.get('/edit', editRoutes.index);
app.get('/service/get-collection-items', serviceRoutes.getCollectionItemsForSelection);