-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow adding projects and bring back the main list
- Loading branch information
Showing
12 changed files
with
417 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 2020 | ||
}, | ||
"rules": { | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
], | ||
"no-console": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* jshint node:true */ | ||
|
||
'use strict'; | ||
|
||
const url = require('url'); | ||
|
||
/* | ||
* CORS middleware | ||
* | ||
* options can contains a list of origins | ||
*/ | ||
module.exports = function cors(options) { | ||
options = options || { }; | ||
const maxAge = options.maxAge || 60 * 60 * 25 * 5; // 5 days | ||
const origins = options.origins || [ '*' ]; | ||
const allowCredentials = options.allowCredentials || false; // cookies | ||
|
||
return function (req, res, next) { | ||
let requestOrigin = req.headers.origin; | ||
if (!requestOrigin) return next(); | ||
|
||
requestOrigin = url.parse(requestOrigin); | ||
if (!requestOrigin.host) return res.status(405).send('CORS not allowed from this domain'); | ||
|
||
const hostname = requestOrigin.host.split(':')[0]; // remove any port | ||
const originAllowed = origins.some(function (o) { return o === '*' || o === hostname; }); | ||
if (!originAllowed) { | ||
return res.status(405).send('CORS not allowed from this domain'); | ||
} | ||
|
||
// respond back with req.headers.origin which might contain the scheme | ||
res.header('Access-Control-Allow-Origin', req.headers.origin); | ||
res.header('Access-Control-Allow-Credentials', allowCredentials); | ||
|
||
// handle preflighted requests | ||
if (req.method === 'OPTIONS') { | ||
if (req.headers['access-control-request-method']) { | ||
res.header('Access-Control-Allow-Methods', 'GET, PUT, DELETE, POST, OPTIONS'); | ||
} | ||
|
||
if (req.headers['access-control-request-headers']) { | ||
res.header('Access-Control-Allow-Headers', req.headers['access-control-request-headers']); | ||
} | ||
|
||
res.header('Access-Control-Max-Age', maxAge); | ||
|
||
return res.status(200).send(); | ||
} | ||
|
||
if (req.headers['access-control-request-headers']) { | ||
res.header('Access-Control-Allow-Headers', req.headers['access-control-request-headers']); | ||
} | ||
|
||
next(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.