[英]How to serve index.html static file from client-side within expressJS server?
I have a dist/index.html
file generated by Webpack to serve the user. 我有一个由Webpack生成的
dist/index.html
文件来为用户服务。
I also have a nodeJs server which want to serve static files from server include index.html from server. 我也有一个nodeJs服务器,它想从服务器提供静态文件,包括服务器提供的index.html。
app.use(express.static('server-side-public-folder'))
router.get('/*', (req, res) => {
res.render('index.html', {secret: secret1});
});
Is there any way to serve index.html
from client-side instead of server-side like this? 有没有办法像这样从客户端而非服务器端提供
index.html
?
app.use(express.static('http://remote.com'))
router.get('/*', (req, res) => {
res.render('http://remote.com/index.html', {secret: secret1});
});
thanks! 谢谢!
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. 通常,通过托管,您可以向一些DNS提供商(例如GoDaddy)注册DNS信息:“ remote.com”。 From there you could point that at your home network/server via your Fios/Comcast allocated IP.
从那里,您可以通过Fios / Comcast分配的IP将其指向家庭网络/服务器。 Be aware that if you are not 'business class' the IP address tends to change every so often.
请注意,如果您不是“企业级”,则IP地址会经常更改。
If you don't want to deal with all that, check out the ones listed above or Heroku (which is free). 如果您不想处理所有这些,请查看上面列出的内容或Heroku(免费)。
I think you are confused 我觉得你很困惑
if you already have index.html in your dist folder you can use express.static('dist') which would automatically render index.html file. 如果dist文件夹中已经有index.html,则可以使用express.static('dist'),它会自动呈现index.html文件。
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. 如果要从没有直接访问权的第三方获取index.html,则必须使用“ http”模块或其他npm库来获取它。 (make sure you have their permission)
(确保获得他们的许可)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.