简体   繁体   中英

Headers is not defined. When running angular universal

ERROR ReferenceError: Headers is not defined

when i run the command node dist/server.js it says that Node server listening on http://localhost:4000 . but when i load http://localhost:4000 in the browser, the Headers is not defined error comes

You need to provide a request to your browser code

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM