Skip to content

Instantly share code, notes, and snippets.

@synaptic-cleft
Created March 2, 2020 13:17
Show Gist options
  • Save synaptic-cleft/8a52493117f7e1dcf7193e3b0034a1e0 to your computer and use it in GitHub Desktop.
Save synaptic-cleft/8a52493117f7e1dcf7193e3b0034a1e0 to your computer and use it in GitHub Desktop.
CORS workaround in stub server for axios calls with Authorization header for access token
const express = require('express')
const app = express()
// !!! This is a workaround for local development only. NEVER DO THIS ON PRODUCTION !!! SOC would kill you. And your family.
let allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', 'http://localhost:5000')
res.header('Access-Control-Allow-Headers', 'Authorization')
res.header('Access-Control-Allow-Credentials', 'true')
next()
}
app.use(allowCrossDomain)
// Actual handling of requests would go here...
app.listen(3001)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment