Do the right tweak to this Node code (should be a very small tweak)

Fermé Publié le il y a 5 ans Paiement à la livraison
Fermé Paiement à la livraison

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.

Express JS Node.js

Nº du projet : #17050704

À propos du projet

5 propositions Projet à distance Actif il y a 5 ans

5 freelances font une offre moyenne de 25 $ pour ce travail

mohanedmagdii

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 Plus

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(34 Commentaires)
5.8
Ananth2020

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

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(6 Commentaires)
2.6