2020-12-24 20:46:11 +00:00
|
|
|
const Unit = require('libflitter/Unit')
|
|
|
|
const cors = require('cors')
|
|
|
|
|
|
|
|
class CORSUnit extends Unit {
|
2021-01-02 21:12:29 +00:00
|
|
|
static get services() {
|
|
|
|
return [...super.services, 'output']
|
|
|
|
}
|
|
|
|
|
2020-12-24 20:46:11 +00:00
|
|
|
static get name() {
|
|
|
|
return 'cors'
|
|
|
|
}
|
|
|
|
|
|
|
|
async go(app) {
|
2021-01-02 21:12:29 +00:00
|
|
|
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
|