-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (27 loc) · 690 Bytes
/
index.js
File metadata and controls
31 lines (27 loc) · 690 Bytes
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
/**
* @file index
* @author imcuttle <moyuyc95@gmail.com>
* @date 2018/10/28
*
*/
const express = require('express')
const middleware = require('./lib/middleware')
function liveMarkd(root, opts) {
const { port, baseUrl = '' } = opts || {}
opts = Object.assign({}, opts)
delete opts.port
delete opts.baseUrl
const middle = middleware(root, opts)
if (port) {
const app = express()
// Set up server
baseUrl ? app.use(baseUrl, middle) : app.use(middle)
app.listen(port, () => {
console.log(`LiveMarkd running on http://localhost:${port}${baseUrl}`)
})
return app
}
// Return express middleware
return middle
}
module.exports = liveMarkd