@zoeldevapps/fastify-cors-envregex
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

fastify-cors-envregex

Helper utility to parse and expand regex usually passed in as environment variables to services into a regex format supported by fastify.

const CORS_ORIGINS =
  "http://localhost:*,https://localhost:*,https://*.adahide.io";

// would be converted into
const fce = require("@zoeldevapps/fastify-cors-envregex");

fce.expandAllowedOrigins(
  "http://localhost:*,https://localhost:*,https://*.adahide.io"
);
/*
{
  origin: [
    /^http:\/\/localhost:.*$/,
    /^https:\/\/localhost:.*$/,
    /^https:\/\/.*\.adahide.io$/
  ],
  methods: [ 'GET', 'PUT', 'POST', 'OPTIONS' ],
  credentials: true
}
*/

Usage:

server.register(
  cors,
  getCorsOptions(CORS_ORIGINS, process.env.NODE_ENV !== "production")
);

Readme

Keywords

none

Package Sidebar

Install

npm i @zoeldevapps/fastify-cors-envregex

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

3.37 kB

Total Files

5

Last publish

Collaborators

  • szist