Here is my /etc/hosts file
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 test.localhost
127.0.0.1 demo.localhost
127.0.0.1 test2.localhost
255.255.255.255 broadcasthost
::1 localhost 我所需要的就是能够从url中解析出子域,就像我必须将它存储在会话cookie中供会话使用(目前)一样。到目前为止,我不想做任何花哨的事情,比如设置apis或任何事情。
Express的文档显示,有一个req.subdomains属性将子域作为数组列出,但是对于我的所有本地子域,该数组显示为空。[也就是说,当我进入demo.localhost:3000时,web应用程序肯定会得到服务,但是在第一个get函数中,我调用req.subdomains,并且有一个空数组[]。
如何从本地主机获得这些子域字符串:3000?
发布于 2015-03-19 14:08:44
这是因为您的主机缺少一个TLD。From the Express code --子域偏移量默认为2,因为它期望类似于.com的内容,而不是主机以localhost结尾。
您可以使用this.app.set('subdomain offset', 1);作为本地运行配置的一部分。
https://stackoverflow.com/questions/29146489
复制相似问题