allow any domain config setting

This commit is contained in:
mrjvs 2023-11-05 13:29:12 +01:00
parent 241b1b1f47
commit b1a79242aa
3 changed files with 8 additions and 2 deletions

View File

@ -2,7 +2,7 @@ import { FragmentSchema } from '@/config/fragments/types';
export const devFragment: FragmentSchema = {
server: {
cors: 'http://localhost:5173',
allowAnySite: true,
trustProxy: true,
},
logging: {

View File

@ -9,6 +9,10 @@ export const configSchema = z.object({
// space seperated list of allowed cors domains
cors: z.string().default(''),
// disable cross origin restrictions, allow any site.
// overwrites the cors option above
allowAnySite: z.coerce.boolean().default(false),
// should it trust reverse proxy headers? (for ip gathering)
trustProxy: z.coerce.boolean().default(false),

View File

@ -56,8 +56,10 @@ export async function setupFastify(): Promise<FastifyInstance> {
// plugins
log.info(`setting up plugins`, { evt: 'setup-plugins' });
const corsDomains = conf.server.cors.split(' ').filter((v) => v.length > 0);
const corsSetting = conf.server.allowAnySite ? true : corsDomains;
await app.register(cors, {
origin: conf.server.cors.split(' ').filter((v) => v.length > 0),
origin: corsSetting,
credentials: true,
});