Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

javascript - 如何在EJS(和Webpack下)中显示主机名(How to display hostname in EJS (and under webpack))

I working under a webpack solution and using EJS to render my pages and i want to display the hostname (my-domain.com) in the render by the EJS file and avoid to inject from a all_script.js like file

(我在webpack解决方案下工作,并使用EJS渲染页面,我想通过EJS文件在渲染中显示主机名(my-domain.com),并避免从all_script.js之类的文件中注入)

I've tried things like this and that's actually not worked :

(我已经尝试过类似的事情,但这实际上是行不通的:)

<%= window.location.hostname %>

The expected result would be "my-domain.com"(预期的结果将是“ my-domain.com”-->)

  ask by PedroZorus translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have finally found an alternative solution :

(我终于找到了替代解决方案:)

If we think about it: the only result we can get is a local hostname.

(如果我们考虑一下:我们可以获得的唯一结果是本地主机名。)

So if we really need to get to future hostname, we are going topass it like a parameter by the webpack config.

(因此,如果我们真的需要获取将来的主机名,我们将通过webpack配置将其像参数一样传递。)

https://stackoverflow.com/a/59127401/12084219

(https://stackoverflow.com/a/59127401/12084219)

In the case in the previous link replace the JSON by a simple string containing the URL.

(在上一个链接的情况下,将JSON替换为包含URL的简单字符串。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...