Skip to content
This repository was archived by the owner on Oct 6, 2024. It is now read-only.

zoeldevapps/fastify-cors-envregex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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")
);

About

fastify cors support with regex envvars

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors