4.0.25 • Published 2 years ago
get-cors-origin v4.0.25
get-cors-origin
get-cors-origin parses any value into a cors configuration if possible.
Status
Category | Status |
---|---|
Version | |
Dependencies | |
Dev dependencies | |
Build | |
License |
Installation
$ npm install get-cors-origin
Quick start
First you need to add a reference to get-cors-origin to your application:
const { getCorsOrigin } = require('get-cors-origin');
If you use TypeScript, use the following code instead:
import { getCorsOrigin } from 'get-cors-origin';
Then you can call the getCorsOrigin
function to parse any value into a configuration suitable for the cors module if possible:
- If you provide a
*
as parameter, you just get*
back. - If you provide one or more domains as parameters in an array, you get an array of sanitized domains back.
- If you provide a domain as a string that contains a regular expression, the string is converted to a regular expression.
- If you provide anything else, an error will be thrown.
Additionally, any whitespace is removed:
const corsOrigin = getCorsOrigin('*');
// => '*'
const corsOrigin = getCorsOrigin([
'http://www.thenativeweb.io',
'http://www.example.com'
]);
// => [
// 'http://www.thenativeweb.io'
// 'http://www.example.com'
// ]
const corsOrigin = getCorsOrigin([
'http://www.thenativeweb.io',
'/\\.thenativeweb\\.io$/'
]);
// => [
// 'http://www.thenativeweb.io'
// /\.thenativeweb\.io$/
// ]
const corsOrigin = getCorsOrigin([
' http://www.thenativeweb.io ',
' /\\.thenativeweb\\.io$/ '
]);
// => [
// 'http://www.thenativeweb.io'
// /\.thenativeweb\.io$/
// ]
const corsOrigin = getCorsOrigin(true);
// => error
const corsOrigin = getCorsOrigin('http://www.thenativeweb.io');
// => error
const corsOrigin = getCorsOrigin(123);
// => error
Running quality assurance
To run quality assurance for this module use roboter:
$ npx roboter
4.0.25
2 years ago
4.0.24
3 years ago
4.0.23
3 years ago
4.0.22
3 years ago
4.0.21
3 years ago
4.0.20
3 years ago
4.0.19
3 years ago
4.0.18
3 years ago
4.0.17
3 years ago
4.0.16
3 years ago
4.0.15
3 years ago
4.0.14
3 years ago
4.0.13
3 years ago
4.0.12
3 years ago
4.0.11
3 years ago
4.0.10
3 years ago
4.0.9
3 years ago
4.0.8
3 years ago
4.0.7
3 years ago
4.0.6
4 years ago
4.0.5
4 years ago
4.0.4
4 years ago
4.0.3
4 years ago
4.0.2
4 years ago
4.0.1
4 years ago
4.0.0
4 years ago
3.0.0
4 years ago
2.0.0
5 years ago
1.0.0
6 years ago