zoukankan      html  css  js  c++  java
  • nodejs 配置代理服务器

    const express = require('express');
    const proxy = require('http-proxy-middleware');
    const cors = require('cors');
    var app = express();
    
    
    app.use(cors({
        credentials: true, 
        optionsSuccessStatus: 200,    
        origin: 'http://localhost:8080' // 设置为项目所在服务器目录(允许跨域请求的网址)
    }));
    
    
    
    app.use('/api', proxy({
        target:'http://192.168.31.65:8000/', // 服务器api地址目录
        changeOrigin: true,
        pathRewrite:{
            "^/api":""
        }
    }));
    
    app.listen(3000,'192.168.31.65', function(){ // 代理接口
        console.log('代理接口启动成功');
    })
    
    // 例如 api接口为 http://192.168.31.65:8000/api/getid/a
    // 实际应该请求的地址为 http://192.168.31.65:3000/api/getid/a
  • 相关阅读:
    day32-python阶段性复习六
    golang 项目中坑
    golang crawler
    router
    golang in ubuntu
    go channel 案例分析
    go channel learning
    bee go + mgo
    URL escape and unescape
    [转]good sample of Go
  • 原文地址:https://www.cnblogs.com/litings/p/10575814.html
Copyright © 2011-2022 走看看