【问题标题】:Headers is not defined. When running angular universal标头未定义。运行角度通用时
【发布时间】:2019-06-03 21:05:35
【问题描述】:
ERROR ReferenceError: Headers is not defined

当我运行命令 node dist/server.js 时,它说节点服务器正在侦听http://localhost:4000。但是当我在浏览器中加载http://localhost:4000 时,标题未定义错误来了

【问题讨论】:

    标签: node.js angular angular-universal


    【解决方案1】:

    您需要向您的浏览器代码提供请求

    app.browser.module.ts

    ...
    // the Request object only lives on the server
    export function getRequest(): any {
      return { headers: { cookie: document.cookie } };
    }
    ...
    
     providers: [
        {
          // The server provides these in main.server
          provide: REQUEST,
          useFactory: getRequest,
        },
        { provide: 'ORIGIN_URL', useValue: location.origin },
      ],
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-26
      • 1970-01-01
      • 2015-09-30
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      • 2020-11-20
      • 2015-10-08
      相关资源
      最近更新 更多