简体   繁体   中英

How to serve index.html static file from client-side within expressJS server?

Front-end:

I have a dist/index.html file generated by Webpack to serve the user.

Back-end nodeJs server side:

I also have a nodeJs server which want to serve static files from server include index.html from server.

app.use(express.static('server-side-public-folder'))
router.get('/*', (req, res) => {
    res.render('index.html', {secret: secret1});
});

Question:

Is there any way to serve index.html from client-side instead of server-side like this?

app.use(express.static('http://remote.com'))
router.get('/*', (req, res) => {
    res.render('http://remote.com/index.html', {secret: secret1});
});

thanks!

Probably static sites hosting is what you need. Look for these:

1) Netlify (my favorite)

2) Zeit

3) Firebase Cloud

If I understand your question, you want to "Host" a website?

Typically with hosting you would register your DNS info: "remote.com", with some DNS provider like GoDaddy. From there you could point that at your home network/server via your Fios/Comcast allocated IP. Be aware that if you are not 'business class' the IP address tends to change every so often.

If you don't want to deal with all that, check out the ones listed above or Heroku (which is free).

I think you are confused

  1. if you already have index.html in your dist folder you can use express.static('dist') which would automatically render index.html file.

  2. if you want to get index.html from thirdparty that you don't have direct access you have to get it by using 'http' module or other npm libraries. (make sure you have their permission)

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