4.0.25 • Published 3 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
3 years ago
4.0.24
4 years ago
4.0.23
4 years ago
4.0.22
4 years ago
4.0.21
4 years ago
4.0.20
4 years ago
4.0.19
4 years ago
4.0.18
4 years ago
4.0.17
4 years ago
4.0.16
4 years ago
4.0.15
4 years ago
4.0.14
4 years ago
4.0.13
4 years ago
4.0.12
4 years ago
4.0.11
4 years ago
4.0.10
4 years ago
4.0.9
5 years ago
4.0.8
5 years ago
4.0.7
5 years ago
4.0.6
5 years ago
4.0.5
5 years ago
4.0.4
5 years ago
4.0.3
5 years ago
4.0.2
5 years ago
4.0.1
5 years ago
4.0.0
6 years ago
3.0.0
6 years ago
2.0.0
6 years ago
1.0.0
7 years ago