首页
学习
活动
专区
圈层
工具
发布

角子域
EN

Stack Overflow用户
提问于 2019-05-28 09:47:48
回答 1查看 3.1K关注 0票数 0

我试图用下面的方法在角6中创建子域。

例如,

本地主机:4200

client1.localhost:4200

client2.localhost:4200

代码语言:javascript
复制
  getSubdomain() {
    const domain = window.location.hostname;
    if (domain.indexOf('.') < 0 
       || domain.split('.')[0] === 'example' 
       || domain.split('.')[0] === 'lvh' 
       || domain.split('.')[0] === 'www') {
       this.subdomain = '';
    } else {
       this.subdomain = domain.split('.')[0];
    }
    console.log('subdomain', this.subdomain);
  }
  1. 运行“ng serve -禁用--主机--检查”命令时,它工作正常。但这不是安全的方法。
  2. 当运行'ng serve‘命令时,会显示“无效主机标题”错误消息。

请建议我任何其他选择,以创建一个角6的子域。

EN

回答 1

Stack Overflow用户

发布于 2019-05-28 10:03:16

出于开发目的,您可以在etc/host文件中添加子域(C:\Windows\System32 32\驱动器\etc\host),如下所示。

代码语言:javascript
复制
127.0.0.1       client1
::1         client1
127.0.0.1       client2
::1         client2

使用命令送达应用程序:-

代码语言:javascript
复制
ng serve --host client1 --port 4300 --open
ng serve --host client2 --port 4400 --open
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56339417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档