lintry

绑定端口参数化

......@@ -6,6 +6,9 @@
const customize = require('kml-customize');
const configure = customize({
"system": {
"bind_port": 8200,
},
"md": {
"base_path": "md",
"default_md": "readme.md",
......
const express = require('express');
const app = express();
const config = require('./init/config').md;
const config = require('./init/config');
const mdview = new (require('./lib/mdview')),
path = require('path');
const MARKDOWN_FILE_BASE = path.resolve(process.cwd(), config.base_path);
const MARKDOWN_FILE_BASE = path.resolve(process.cwd(), config.md.base_path);
app.use(express.static(__dirname + '/themes'));
app.use(express.static(MARKDOWN_FILE_BASE));
......@@ -14,7 +14,7 @@ app.use(express.static(MARKDOWN_FILE_BASE));
function sendTemplate (filename, theme) {
//默认md
if (!filename || filename.match(/.+\/$/)) {
filename = (filename || '') + config.default_md
filename = (filename || '') + config.md.default_md
}
let file = path.resolve(MARKDOWN_FILE_BASE, filename);
if (!path.parse(file).ext) {
......@@ -22,7 +22,7 @@ function sendTemplate (filename, theme) {
file += '.md'
}
let result = mdview.renderFile(file);
theme = theme || config.theme;
theme = theme || config.md.theme;
return `
<!DOCTYPE html>
<html>
......@@ -47,6 +47,6 @@ app.get('/**', function (req, res) {
res.send(sendTemplate(urls[1], query.t));
})
const PORT = 3000;
const PORT = config.system.bind_port;
app.listen(PORT);
console.info(`Server is started up by binding ${PORT}. Visit http://localhost:${PORT}`);
......