UNPKG

492 BJavaScriptView Raw
1const getConfig = require('../conf/get')
2module.exports = (req, resp, next) => {
3 // 获取 host & port
4 let [hostname, port = 80] = (req.headers.host + '').split(':')
5 if (req.client.ssl) {
6 port = 443
7 }
8
9 // 获取 config
10 const conf = getConfig(hostname, port)
11 const {
12 handleError
13 } = require('../util/resp')(conf)
14 if (!conf) {
15 handleError(resp, {error: 'host not found!'})
16 } else {
17 conf.app(req, resp, next, conf)
18 }
19}