Skip to content

Commit

Permalink
fix(webpack): url parse error under proxy #34
Browse files Browse the repository at this point in the history
  • Loading branch information
njugray authored and devrsi0n committed Mar 21, 2018
1 parent 81f50fb commit 63d952f
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions packages/beidou-webpack/app/middleware/webpack.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
'use strict';

const url = require('url');
const URL = require('url-parse');
const request = require('request');
const debug = require('debug')('beidou-webpack');

module.exports = function (options, app) {
return async function (ctx, next) {
if (!app.webpackServerPort) return next();
let webpackUrl = ctx.request.href.replace(
url.parse(ctx.request.href).port,
app.webpackServerPort
);
const originUrl = `http://${ctx.host}${ctx.request.url}`;
const url = new URL(originUrl);
url.set('port', app.webpackServerPort);
const webpackUrl = url.href;

// force to use `http` protocol, because webpack does not support https
webpackUrl = webpackUrl.replace(/^https/, 'http');
const webpackRequest = request(webpackUrl);
const notFound = await new Promise((resolve) => {
webpackRequest.on('response', function (res) {
Expand Down

0 comments on commit 63d952f

Please sign in to comment.