-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
35 lines (32 loc) · 967 Bytes
/
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
'use strict'
const express = require('express')
const path = require('path')
const buildSite = require('./lib/template')
const cli = require('./lib/cli')
const Config = require('./lib/config')
const db = require('./lib/db')
module.exports = async (_conf) => {
const config = new Config(_conf)
const _db = await db(config.db)
return {
config,
db: _db,
buildIndex: () => {
return db.buildIndex(config, _db)
},
buildSite: () => {
return buildSite(config, _db)
},
serve: () => {
return express()
.use(config.baseUrl, express.static(config.outputDirectory))
.use((req, res) => res.sendFile(path.resolve(config.outputDirectory, '404.html')))
.listen(config.port, () => console.log(`Server listening on http://localhost:${config.port}`))
},
close: () => _db.close()
}
}
module.exports.db = db
module.exports.template = buildSite
module.exports.cli = cli
module.exports.Config = Config