简体   繁体   中英

Serve static file from different server express.js

How to serve static file eg index.html from different server

app.use(express.static(' http://example.com/ '))

A proxy such as http-proxy-middleware can do this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM