Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export defaultAllowedOrigins for user-land config and 3rd party plugins #19259

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

timacdonald
Copy link
Contributor

@timacdonald timacdonald commented Jan 21, 2025

Description

It is not currently possible to widen the shipped allowed origins. A user or plugin must completely replace them defaults. The current value could be copy and pasted from core, but could then get out of sync.

This PR allows both user-land applications and 3rd-party plugins to augment the default allowed origins that ship with Vite without worrying about drift.

import { defineConfig, defaultAllowedOrigins } from 'vite';

export default defineConfig({
    server: {
        cors: {
            origin: [
                defaultAllowedOrigins,
                'my-app.com',
            ],
        }
    }
});

Future proofing question

Should we make the defaultAllowedOrigins constant an array? I can imagine that this might slowly get more things added to the regex and it could become to maintain as a single regex expression. Having it as an array from the outset might help future proof if you ever want to split the pattern into diffe.

origin: [
    ...defaultAllowedOrigins,
    'my-app.com',
],

@timacdonald timacdonald changed the title Export defaultAllowedOrigins for 3rd party plugins feat: export defaultAllowedOrigins for user-land config and 3rd party plugins Jan 21, 2025
Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed today that it's better to merge this one in 6.1, but let's us know if you need it before and we can recheck this.

@patak-dev patak-dev added this to the 6.1 milestone Jan 22, 2025
@timacdonald
Copy link
Contributor Author

No rush on my end. I've copied the value over manually for now.

This will just help with future proofing.

@patak-dev patak-dev merged commit dc8946b into vitejs:main Jan 23, 2025
15 of 17 checks passed
@timacdonald timacdonald deleted the export-defaultAllowedOrigins branch January 23, 2025 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants