CORS policy access

This commit is contained in:
2022-04-20 20:26:14 -03:00
parent 4636558d3b
commit 094442c1a9
2 changed files with 22 additions and 6 deletions

View File

@@ -1,11 +1,27 @@
const Express = require('express')
const app = Express()
const port = (process.env.PORT || 3030)
const port = (process.env.PORT || 5050)
require('dotenv').config()
//Enable CORS
const cors = require('cors');
app.use(cors())
// Add headers before the routes are defined
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');
// 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();
});
//Configure Handlebars
const hbs = require('hbs')

View File

@@ -3,7 +3,7 @@ const router = Express.Router()
const axios = require('axios')
router.get('/', async (req, res) => {
router.post('/', async (req, res) => {
async function requestAccessToken() {
try {
@@ -45,7 +45,7 @@ router.get('/', async (req, res) => {
}
catch (error) {
console.log(error)
return {status: 400}
return {status: 400, body: {data: error.response.data.error}}
}
}