Last active
September 14, 2025 12:26
-
-
Save yeyuguo/a6364127ccb1ee90fe521f0967ff447e to your computer and use it in GitHub Desktop.
express server 和 代理 proxy 插件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // pnpm install http express express-http-proxy | |
| var express = require('express'); | |
| var http = require('http') | |
| var app = express(); | |
| var http_app = http.Server(app); | |
| var proxy = require('express-http-proxy') | |
| const remote = proxy("真实接口地址", { | |
| limit: '10mb', | |
| proxyReqPathResolver: function (req, res) { | |
| return req._parsedUrl.path | |
| }, | |
| }) | |
| app.use('/api/', remote) | |
| app.use('/', express.static('dist/')); | |
| var server = http_app.listen(8080, function () { | |
| var host = server.address().address; | |
| var port = server.address().port; | |
| console.log('Server running at http://%s:%s', host, port); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment