mirror of
https://github.com/FranP-code/Open-Telegram-to-Notion-Backend.git
synced 2025-10-12 23:52:54 +00:00
CORS policy access
This commit is contained in:
24
src/index.js
24
src/index.js
@@ -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')
|
||||
|
||||
@@ -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}}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user