Skip to content

Throwing Cros on Angular UNIVERSAL .  #1

Description

@kakul232

Hi , Its Works perfetly on Angular 5 , But when i switch it to universal its throwing

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://newsapi.org/v2/top-headlines?country=in&category=technology&pageSize=5. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Unhandled rejection 9jcD/</h.prototype._onFinish/d.onerror@http://localhost:4000/main.5b638d685502c047f09e.bundle.js:1:230171
D@http://localhost:4000/polyfills.2749d91dc0f503fb6b5e.bundle.js:1:35067
eFQL/</</</c</t.prototype.invokeTask@http://localhost:4000/polyfills.2749d91dc0f503fb6b5e.bundle.js:1:26386
onInvokeTask@http://localhost:4000/main.5b638d685502c047f09e.bundle.js:1:558505
eFQL/</</</c</t.prototype.invokeTask@http://localhost:4000/polyfills.2749d91dc0f503fb6b5e.bundle.js:1:26299
eFQL/</</</o</e.prototype.runTask@http://localhost:4000/polyfills.2749d91dc0f503fb6b5e.bundle.js:1:21556
eFQL/</</</u</e.invokeTask@http://localhost:4000/polyfills.2749d91dc0f503fb6b5e.bundle.js:1:27480
_@http://localhost:4000/polyfills.2749d91dc0f503fb6b5e.bundle.js:1:38181
k@http://localhost:4000/polyfills.2749d91dc0f503fb6b5e.bundle.js:1:38413

I have setting up my server.ts with this following code but not fixed yet

app.use(function (req, res, next) {

  // Website you wish to allow to connect
  res.setHeader('Access-Control-Allow-Origin', '*');

  // Request methods you wish to allow
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');

  // Request headers you wish to allow
  res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type,accept');

  // Set to true if you need the website to include cookies in the requests sent
  // to the API (e.g. in case you use sessions)
  res.setHeader('Access-Control-Allow-Credentials', true);

  // Pass to next layer of middleware
  next();
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions