backend/app/CORSUnit.js

33 lines
903 B
JavaScript
Raw Normal View History

2020-12-24 20:46:11 +00:00
const Unit = require('libflitter/Unit')
const cors = require('cors')
class CORSUnit extends Unit {
static get services() {
return [...super.services, 'output']
}
2020-12-24 20:46:11 +00:00
static get name() {
return 'cors'
}
async go(app) {
app.express.use(cors({
origin: (origin, callback) => {
const allowed = [
'https://noded.garrettmills.dev',
'https://noded-dev.garrettmills.dev',
'http://noded.garrettmills.dev',
'http://noded-dev.garrettmills.dev',
'http://localhost:8000',
'http://localhost:8100'
]
if ( allowed.includes(origin) || !origin ) callback(null, true)
else callback(new Error('Invalid origin.'))
}
}))
2020-12-24 20:46:11 +00:00
}
}
module.exports = exports = CORSUnit