标头未定义。在运行角度通用时

时间:2019-01-09 06:17:37

标签: node.js angular angular-universal

ERROR ReferenceError: Headers is not defined

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

1 个答案:

答案 0 :(得分:0)

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

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 },
  ],