nodejs express框架实现一个反向代理访问网站效果代码
代码语言:nodejs
所属分类:通讯
代码描述:nodejs express框架实现一个反向代理访问网站效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
const request = require('request'); const express = require('express'); const path = require('path'); const app = express(); const proxyTable = { '/test': { target: 'http://baidu.com/test' } }; app.use(function(req, res,next) { const url = req.url; if (req.method == 'OPTIONS') { console.log('options_url: ', url); // res.header("Access-Control-Allow-Origin", req.headers.origin || '*'); // res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With"); // res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); // res.header("Access-Control-Allow-Credentials", true); res.status(200).send('OK'); return; } // console.log('req_url: ', url); next(); }); //app.use(express.static(path.join(__dirname,.........完整代码请登录后点击上方下载按钮下载查看
网友评论0