node set up a proxy server

Need to use even a package, express, http-proxy-middleware

var Express = the require ( 'Express' )
 var Proxy = the require ( 'HTTP-Proxy-Middleware' )
 var App = Express (); 

app.all ( "*", function (REQ, RES, Next) {
     // set allows cross-domain name, the domain cross-domain allows any * represents 
    res.header ( "Access-Control-the allow-Origin", "*" );
     // allows the header type 
    res.header ( "Access-Control-allow -Headers" , "Content-type" );
     // cross-domain request allows manner 
    res.header ( "Access-Control-the allow-Methods", "the DELETE, the PUT, the POST, the GET, the OPTIONS" ); 
   
        Next ();
})

let a=proxy({
    target:'http://api.zhuishushenqi.com' , 
    changeOrigin: to false , 
    pathRewrite: {
         "^ / API": "" 
    } 
}) 

app.use ( '/' , A) 

app.listen ( 5000, function () { 
    the console.log ( 'server startup success' ) 
})

 

Guess you like

Origin www.cnblogs.com/zs521/p/11864198.html