Skip to content

Instantly share code, notes, and snippets.

@rajaramtt
Created October 31, 2018 13:31
Show Gist options
  • Save rajaramtt/195628feb92e4609581fc8cc6ca782b8 to your computer and use it in GitHub Desktop.
Save rajaramtt/195628feb92e4609581fc8cc6ca782b8 to your computer and use it in GitHub Desktop.
CORS headers in node, php
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:4200');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
@rajaramtt
Copy link
Author

For php

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 1000");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding");
header("Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS, DELETE");

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