Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {PassThrough} = require('stream');
- protocol.registerStreamProtocol('app', ((request, callback) => {
- let url = new murl.URL(request.url);
- let newUrlOptions = {
- auth: url.auth,
- hash: url.hash,
- host: webpackDevServerUrl.host,
- hostname: url.hostname,
- href: url.href,
- path: url.path,
- pathname: url.pathname,
- protocol: webpackDevServerUrl.protocol,
- search: url.search,
- slashes: url.slashes,
- port: webpackDevServerUrl.port,
- query: url.query,
- };
- let newUrl = murl.format(newUrlOptions);
- const netRequest = net.request({
- method: 'GET',
- url: newUrl
- });
- netRequest.on('response', response => {
- console.log("netRequest response");
- const rv = new PassThrough();
- callback({
- statusCode: response.statusCode,
- headers: response.headers,
- data: rv
- });
- response.on('data', chunk => {
- rv.push(chunk);
- });
- response.on('end', () => {
- rv.push(null);
- });
- });
- netRequest.on('abort', () => {
- console.log("netRequest abort");
- callback({
- statusCode: 501
- })
- });
- netRequest.on('error', (error) => {
- console.log("netRequest error", error);
- callback({
- statusCode: error.code
- })
- });
- netRequest.end();
- }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement