Do the right tweak to this Node code (should be a very small tweak)
$10-30 USD
착불
What you will do:
Minimum modifications to the following code to make it works.
See the bottom of this text.
Please, do not create a new code from scratch.
This code is almost fine, just need the right tweak.
Setup:
$ npm i --save express http http-proxy-middleware
$ node [login to view URL]
file: [login to view URL]
// BEGIN OF CODE
var express = require('express');
var http = require('http');
var proxy = require('http-proxy-middleware');
function bodyTransform(body) {
body = [login to view URL]('is running', 'is now running');
body = [login to view URL]('3001', '3002');
return body;
}
var onProxyRes = (proxyRes, req, res) => {
const _writeHead = [login to view URL];
const _end = [login to view URL];
var buffer = new Buffer('');
let body = '';
[login to view URL]('data', (chunk) => {
[login to view URL]("inside: .on('data', ...)");
buffer = [login to view URL]([buffer, chunk]);
});
[login to view URL]('end', () => {
[login to view URL]("inside: .on('end', ...)");
body = [login to view URL]('utf8');
});
// defer writeHead
[login to view URL] = (...writeHeadArgs) => {
const output = bodyTransform(body);
if ([login to view URL] && [login to view URL]['content-length']) {
// if 'content-length' is set to: '[login to view URL]' it causes:
// ERR_CONTENT_LENGTH_MISMATCH (Google Chrome is explicit about the error)
// because it seems that the actual content output is an empty string (length: 0)
[login to view URL]('content-length', [login to view URL]);
[login to view URL]('assigned => content-length: ' + [login to view URL]);
// if the following line is uncommented, there are no errors
// because it seems that the actual content output is an empty string (length: 0)
// so the 'content-length' will match
// [login to view URL]('content-length', 0);
}
// disabling chunked encoding
[login to view URL]('transfer-encoding', '');
// disabling cache for all http as well
[login to view URL]('cache-control', 'no-cache');
[login to view URL](res, writeHeadArgs);
};
// defer all writes
[login to view URL] = (chunk) => { };
[login to view URL] = (...endArgs) => {
const output = bodyTransform(body);
if ([login to view URL]) {
[login to view URL](res, [output]);
}
else {
[login to view URL](res, endArgs);
}
[login to view URL]('after: [login to view URL](...);');
};
}
const portApp01 = 3001;
const app01 = express()
[login to view URL]('/', (req, res) => {
[login to view URL]('This server is running on port: 3001');
});
[login to view URL](portApp01, () => {
[login to view URL]('app01 is listening on port: ' + portApp01);
});
const portProxy = 3002;
const appProxy = express()
[login to view URL](proxy('/', { target: 'http://localhost:3001', onProxyRes: onProxyRes }));
[login to view URL](appProxy).listen(portProxy, function () {
[login to view URL]('appProxy is listening on port: ' + portProxy);
});
// END OF CODE
For initial test:
Go to the following url on the browser:
http://localhost:3001
The browser outputs: 'This server is running on port: 3001'
Goal of your modification:
Do the minimal modifications to the code above in order to:
When going to the following url on the browser:
http://localhost:3002
The browser should output: 'This server is now running on port: 3002'
There are some comments in the code that are explicit about the current issue of this code.
프로젝트 ID: #17050704
프로젝트 소개
이 일자리에 대한 프리랜서 5 명의 평균 입찰가: $25
Hey Sir, I am interested in your project.I am good in node.js and I can help you and I am ready to start the work right now, and will deliver with good result to you. please send me a message so that we can discuss 기타
Hi, I have almost 4 years of experience as nodejs developer, I saw your description I can help you on this, I need to clarify some queries, just ping me if you're ok, Thanks