Este grupo de trabajo ha estado por horas buscando soluciones a tus preguntas, te ofrecemos la solución así que esperamos servirte de mucha ayuda.
Ejemplo 1: opción http-proxy-middleware.onProxyReq:
'use strict';var express =require('express');var router = express.Router();varproxy_filter=function(path, req);var proxy_options =
target:'http://localhost:8080',
pathRewrite:'^/docs':'/java/rep/server1'// Host path & target path conversion,onError(err, req, res)
res.writeHead(500,'Content-Type':'text/plain');
res.end('Something went wrong. And we are reporting a custom error message.'+ err);,onProxyReq(proxyReq, req, res)if( req.method=="POST"&& req.body)// Add req.body logic here if needed....// ....// Remove body-parser body object from the requestif( req.body)delete req.body;// Make any needed POST parameter changeslet body =newObject();
body.filename='reports/statistics/summary_2016.pdf';
body.routeid='s003b012d002';
body.authid='bac02c1d-258a-4177-9da6-862580154960';// URI encode JSON object
body =Object.keys( body ).map(function(key)returnencodeURIComponent( key )+'='+encodeURIComponent( body[ key ])).join('&');// Update header
proxyReq.setHeader('content-type','application/x-www-form-urlencoded');
proxyReq.setHeader('content-length', body.length);// Write out body changes to the proxyReq stream
proxyReq.write( body );
proxyReq.end();;// Proxy configurationvar proxy =require('http-proxy-middleware')( proxy_filter, proxy_options );/* GET home page. */
router.get('/',function(req, res, next)
res.render('index', title:'Node.js Express Proxy Test'););
router.all('/document', proxy );
module.exports= router;
Ejemplo 2: middleware de proxy http
// TIPS AND TRICK CUSTOM PROXY IN WEBPACK DEV SERVER BY restuwahyu13//NOTE this method like using CRA in React// manual proxy before
module.exports=
devServer:
open:true,
compress:true,
hot:true,
inline:true,
lazy:true,
contentBase:resolve(process.cwd(),'build'),
port: process.env.PORT// custom proxy after
module.exports=
devServer:
Reseñas y valoraciones de la guía
Eres capaz de añadir valor a nuestro contenido participando con tu veteranía en las referencias.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)