mirror of
https://github.com/samsonjs/mit-license.git
synced 2026-03-25 09:25:49 +00:00
refactor: Use external cors implementation
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
parent
64480c9879
commit
e64cbf6a3d
5 changed files with 5 additions and 9 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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('.')
|
||||
|
||||
|
|
|
|||
|
|
@ -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
BIN
yarn.lock
Binary file not shown.
Loading…
Reference in a new issue