mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-07 19:08:34 +03:00
making cors customizable
This commit is contained in:
16
src/index.js
16
src/index.js
@@ -7,6 +7,14 @@ import api from './api'
|
||||
import dotenv from 'dotenv'
|
||||
const hbs = require('express-handlebars')
|
||||
|
||||
|
||||
let configJS
|
||||
try {
|
||||
configJS = require('./local.config.js').default
|
||||
} catch (_) {
|
||||
configJS = require('./config.js').default
|
||||
}
|
||||
|
||||
dotenv.config()
|
||||
|
||||
let app = express()
|
||||
@@ -17,13 +25,17 @@ app.engine('.hbs', hbs({
|
||||
}))
|
||||
app.set('view engine', '.hbs')
|
||||
|
||||
// enable cross origin requests explicitly in development
|
||||
// enable cross origin requests explicitly in development OR if active in prod
|
||||
const cors = require('cors')
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
const cors = require('cors')
|
||||
console.log('Enabling CORS in development...')
|
||||
app.use(cors())
|
||||
} else if (configJS.cors.active === true) {
|
||||
console.log('Enabling CORS in from config.js in prod...')
|
||||
app.use(cors(configJS.cors.corsOptions))
|
||||
}
|
||||
|
||||
|
||||
const config = process.env
|
||||
|
||||
initialize(controller => {
|
||||
|
||||
Reference in New Issue
Block a user