From b048be1a56878a8800c30037e0c227ec31eedc3d Mon Sep 17 00:00:00 2001 From: yutent Date: Sun, 19 Feb 2023 18:12:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE=E4=BA=8C?= =?UTF-8?q?=E7=BA=A7=E7=9B=AE=E5=BD=95=E6=97=B6,=20=E8=87=AA=E5=8A=A8302?= =?UTF-8?q?=E9=87=8D=E5=AE=9A=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/dev.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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('/')