Skip to content

Commit c71539e

Browse files
committed
fix(cli): allow any localhost port in CORS config
When port 3000 is unavailable, Nuxt/Vite automatically picks an alternative port: ``` [get-port] Unable to find an available port (tried 3000 on host "localhost"). Using alternative port 3001. ``` But the connector CORS config was hardcoded to only allow the prod host and `http://localhost:3000`, causing local authentication to fail in an opaque manner. It now uses a regex pattern to allow any localhost port. This seems fine from a security perspective, and there aren't alternatives with great DX that I can think of.
1 parent 2df63c6 commit c71539e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

cli/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function generateOperationId(): string {
3737
}
3838

3939
const corsOptions: CorsOptions = {
40-
origin: ['https://npmx.dev', 'http://localhost:3000'],
40+
origin: ['https://npmx.dev', /^http:\/\/localhost:\d+$/],
4141
methods: ['GET', 'POST', 'DELETE', 'OPTIONS'],
4242
allowHeaders: ['Content-Type', 'Authorization'],
4343
}

0 commit comments

Comments
 (0)