I've inserted the following lines into my code:
var express = require('express'); var cors = require('cors'); var app = express(); app.options('*', cors()); app.use(cors()); However, when I make an AJAX POST request, I still get the error:
POST https://stormy-plateau-94715.herokuapp.com/login new-page-5:1 XMLHttpRequest cannot load https://stormy-plateau-94715.herokuapp.com/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://squareguru.squarespace.com' is therefore not allowed access. The response had HTTP status code 503. This is my first time using the cors package, am I configuring something wrong? I would love any help you guys can give me, thanks!
res.setHeader("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With");app.all('*', function(req, res, next){ res.writeHead(200, {'Content-Type': 'text/html'}); res.header("Access-Control-Allow-Origin", "*"); res.header('Access-Control-Allow-Methods', 'OPTIONS,GET,POST'); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); });I'm still getting the same errorapp.options('*', cors());justapp.use(cors());