From b27e200884884ecb7f74f9a35cf1b47ef1b71938 Mon Sep 17 00:00:00 2001 From: pshu Date: Wed, 25 Sep 2024 01:44:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20work=20around=20dev?= =?UTF-8?q?=20504?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/bundler-mako/index.js | 15 +++------------ packages/bundler-mako/package.json | 1 - 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/bundler-mako/index.js b/packages/bundler-mako/index.js index c9155ed36..45388c4ed 100644 --- a/packages/bundler-mako/index.js +++ b/packages/bundler-mako/index.js @@ -82,10 +82,10 @@ exports.dev = async function (opts) { assert(opts, 'opts should be supplied'); checkConfig(opts); const express = require('express'); - const proxy = require('express-http-proxy'); const app = express(); const port = opts.port || 8000; const hmrPort = opts.port + 1; + const makoConfig = await getMakoConfig(opts); // cors app.use( @@ -118,16 +118,8 @@ exports.dev = async function (opts) { createProxy(opts.config.proxy, app); } - app.use( - proxy(`http://127.0.0.1:${hmrPort}`, { - filter: function (req, res) { - return req.method == 'GET' || req.method == 'HEAD'; - }, - skipToNextHandlerFilter: function (proxyRes) { - return proxyRes.statusCode !== 200; - }, - }), - ); + // serve dist files + app.use(express.static(makoConfig.output.path)); // after middlewares (opts.afterMiddlewares || []).forEach((m) => { @@ -169,7 +161,6 @@ exports.dev = async function (opts) { // mako dev const { build } = require('@umijs/mako'); - const makoConfig = await getMakoConfig(opts); if (process.env.HMR === 'none') { makoConfig.hmr = false; } else { diff --git a/packages/bundler-mako/package.json b/packages/bundler-mako/package.json index e84d9a680..9da24b456 100644 --- a/packages/bundler-mako/package.json +++ b/packages/bundler-mako/package.json @@ -9,7 +9,6 @@ "connect-history-api-fallback": "^2.0.0", "cors": "^2.8.5", "express": "^4.18.2", - "express-http-proxy": "^2.1.1", "get-tsconfig": "4.7.5", "lodash": "^4.17.21", "rimraf": "5.0.1", From b22084f330e4480a2d79259bda343d6e3f9a514e Mon Sep 17 00:00:00 2001 From: pshu Date: Wed, 25 Sep 2024 07:46:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20workaround=20chunk=20?= =?UTF-8?q?serve=20back=20to=20node.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/bundler-mako/index.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/bundler-mako/index.js b/packages/bundler-mako/index.js index 45388c4ed..f14129200 100644 --- a/packages/bundler-mako/index.js +++ b/packages/bundler-mako/index.js @@ -120,6 +120,34 @@ exports.dev = async function (opts) { // serve dist files app.use(express.static(makoConfig.output.path)); + if (process.env.SSU === 'true') { + // for ssu cache chunks + + app.use(function (req, res, next) { + if (req.method !== 'GET' && req.method !== 'HEAD') { + return next(); + } + + let proxy = createProxyMiddleware({ + target: `http://127.0.0.1:${hmrPort}`, + selfHandleResponse: true, + onProxyRes: (proxyRes, req, res) => { + if (proxyRes.statusCode !== 200) { + next(); + } else { + proxyRes.pipe(res); + } + }, + onError: (err, req, res) => { + next(); + }, + }); + + proxy(req, res, () => { + next(); + }); + }); + } // after middlewares (opts.afterMiddlewares || []).forEach((m) => {