forked from jaredly/hexo-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (28 loc) · 1.21 KB
/
index.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
var serveStatic = require('serve-static'),
bodyParser = require('body-parser'),
path = require('path'),
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;
} else if (hexo.config.admin.password_hash.length <= 32) {
throw new Error('[Hexo Admin]: the provided password_hash looks like an md5 hash -- hexo-admin has switched to use bcrypt; see the Readme for more info.')
}
if (!hexo.config.admin.secret) {
console.error('[Hexo Admin]: config admin.secret is requred for authentication');
passwordProtected = false;
}
}
hexo.extend.filter.register('server_middleware', function(app) {
if (passwordProtected) {
require('./auth')(app, hexo); // setup authentication, login page, etc.
}
// Main routes
app.use(hexo.config.root + 'admin/', serveStatic(path.join(__dirname, 'www')));
app.use(hexo.config.root + 'admin/api/', bodyParser.json({limit: '50mb'}));
// setup the json api endpoints
api(app, hexo);
});