diff --git a/lib/dev.js b/lib/dev.js index d10702b..b8a7ca8 100644 --- a/lib/dev.js +++ b/lib/dev.js @@ -53,8 +53,9 @@ export default async function createServer(root = '', conf = {}) { server .on('request', function (req, res) { + let prefix = DEPLOY_PATH ? DEPLOY_PATH.replace(/\/$/, '') : '' let url = - DEPLOY_PATH && req.url.startsWith(DEPLOY_PATH.replace(/\/$/, '')) + prefix && req.url.startsWith(prefix) ? req.url.slice(DEPLOY_PATH.length) : req.url.slice(1) let pathname = parse(url).pathname @@ -62,6 +63,12 @@ export default async function createServer(root = '', conf = {}) { isIndex = false // 是否渲染目录页 let ext + if (prefix && req.url === '/') { + res.setHeader('Location', DEPLOY_PATH) + res.writeHead(302, 'Redirect') + return res.end('') + } + if (pathname) { pathname = pathname.split('/')