[英]Serve static file from different server express.js
How to serve static file eg index.html from different server 如何从其他服务器提供静态文件,例如index.html
app.use(express.static(' http://example.com/ ')) app.use(express.static(' http://example.com/ '))
A proxy such as http-proxy-middleware
can do this: 诸如
http-proxy-middleware
可以做到这一点:
var express = require('express');
var proxy = require('http-proxy-middleware');
var app = express();
app.use('/api', proxy({target: 'http://www.example.org', changeOrigin: true}));
app.listen(3000);
// http://localhost:3000/api/foo/bar -> http://www.example.org/api/foo/bar
see https://www.npmjs.com/package/http-proxy-middleware 参见https://www.npmjs.com/package/http-proxy-middleware
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.