refactor: Use external cors implementation

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
Richie Bendall 2020-03-18 18:21:30 +13:00
parent 64480c9879
commit e64cbf6a3d
No known key found for this signature in database
GPG key ID: 1C6A99DFA9D306FC
5 changed files with 5 additions and 9 deletions

View file

@ -1,8 +0,0 @@
module.exports = (_req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
)
next()
}

View file

@ -28,6 +28,7 @@
"@sindresorhus/is": "^2.0.0",
"any-size": "^1.0.0",
"btoa": "^1.2.1",
"cors": "^2.8.5",
"ejs": "^3.0.1",
"escape-goat": "^3.0.0",
"express": "^4.17.1",

View file

@ -17,8 +17,10 @@ const { validDomainId } = require('./utils')
function getUserData ({ query, body }) {
// If query parameters provided
if (size(query) > 0) return query
// If the data parsed as {'{data: "value"}': ''}
if (size(body) === 1 && !Object.values(body)[0]) return JSON.parse(Object.keys(body)[0])
// Fallback
return body
}
@ -26,6 +28,7 @@ function getUserData ({ query, body }) {
// HTTP POST API
module.exports = async (req, res) => {
const { hostname } = req
// Get different parts of hostname (example: remy.mit-license.org -> ['remy', 'mit-license', 'org'])
const params = hostname.split('.')

View file

@ -48,7 +48,7 @@ app.use(
// Middleware
// CORS
app.use(require('./middleware/cors'))
app.use(require('cors'))
// Parse URL-encoded bodies (as sent by HTML forms)
app.use(
express.urlencoded({

BIN
yarn.lock

Binary file not shown.