forked from jaredly/hexo-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (27 loc) · 1 KB
/
index.js
File metadata and controls
35 lines (27 loc) · 1 KB
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
var serveStatic = require('serve-static');
var bodyParser = require('body-parser');
var filter = hexo.extend.filter;
var path = require('path')
var api = require('./api');
var passwordProtected = hexo.config.admin && hexo.config.admin.username;
// verify that correct config options are set.
if (passwordProtected) {
if (!hexo.config.admin.password_hash) {
console.error('[Hexo Admin]: config admin.password_hash is requred for authentication')
passwordProtected = false
}
if (!hexo.config.admin.secret) {
console.error('[Hexo Admin]: config admin.secret is requred for authentication')
passwordProtected = false
}
}
filter.register('server_middleware', function (app) {
if (passwordProtected) {
// setup authentication, login page, etc.
require('./auth')(app)
}
app.use('/admin/', serveStatic(path.join(__dirname, 'www')));
app.use('/admin/api/', bodyParser.json({limit: '50mb'}))
// setup the json api endpoints
api(app);
});