简体   繁体   中英

Is it possible to set up an API to serve html from another domain?

I'm curious whether if it's possible to set up a server to respond with html fetched from another domain rather than simply redirect the requester to that domain. For example, I set up a simple node express server that has a GET route /google, which fetches google.com, and then responds with the response from the fetch. However, in this case, it does not respond with the google webpage as I would expect.

It is not only possible but quite common especially in larger server environments. The term you are looking for is reverse-proxy.

Proxying is typically used to distribute the load among several servers, seamlessly show content from different websites, or pass requests for processing to application servers over protocols other than HTTP.

Source: https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

Most major web servers support it.

More than likely the response you're getting from google (and passing on) is some kind of redirection. Try it with a static web page of your own to rule out any redirection shenanigans.

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