Skip to content

Commit 3230f9d

Browse files
halskclaude
andauthored
Fix vite.config.ts allowedHosts issue (#185)
* Fix vite.config.ts allowedHosts issue - Fixed an issue where the allowedHosts setting was being converted to a limited array of localhost values instead of allowing all hosts as intended - Updated ServerConfig interface to properly support boolean allowedHosts - Added hostname extraction utility for future use - Improved logging to clearly show when all hosts are allowed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Fix vite.config.ts type issues - Corrected ServerConfig interface to match Vite's expected types - Removed unused variables to fix linting errors - Added detailed comments for future enhancements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent ba7b7fe commit 3230f9d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

frontend/vite.config.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ export default defineConfig(({ mode }) => {
1414
VITE_ADDITIONAL_ALLOWED_HOSTS: env.VITE_ADDITIONAL_ALLOWED_HOSTS,
1515
});
1616

17+
// FUTURE ENHANCEMENT: If we need to extract specific domains to include instead of allowing all:
18+
//
19+
// function extractHostname(url) {
20+
// try {
21+
// return new URL(url).hostname;
22+
// } catch {
23+
// return null;
24+
// }
25+
// }
26+
//
27+
// const ngrokHost = env.VITE_FRONTEND_URL ? extractHostname(env.VITE_FRONTEND_URL) : null;
28+
// const allowedHostsList = ['localhost', '127.0.0.1', ngrokHost].filter(Boolean);
29+
1730
// For development with ngrok, allow all hosts
1831
// This is a more permissive approach that will solve the immediate issue
1932
const allowedHosts = true; // Allow all hosts
@@ -30,7 +43,7 @@ export default defineConfig(({ mode }) => {
3043
clientPort: number;
3144
};
3245
cors: boolean;
33-
allowedHosts: string[];
46+
allowedHosts: string[] | true;
3447
proxy?: {
3548
[key: string]: {
3649
target: string;
@@ -52,8 +65,9 @@ export default defineConfig(({ mode }) => {
5265
clientPort: 5173
5366
},
5467
cors: true,
55-
// Allow connections from these hosts
56-
allowedHosts: typeof allowedHosts === 'boolean' ? ['localhost', '127.0.0.1'] : allowedHosts,
68+
// When allowedHosts is true, keep it as true (allow all hosts)
69+
// Otherwise, ensure we include both localhost and ngrok domains
70+
allowedHosts,
5771
// Initialize proxy as empty object to satisfy TypeScript
5872
proxy: {} as ServerConfig['proxy']
5973
} as ServerConfig
@@ -74,6 +88,6 @@ export default defineConfig(({ mode }) => {
7488
console.log('Production mode: API proxy disabled');
7589
}
7690

77-
console.log('Allowed hosts:', allowedHosts);
91+
console.log('Allowed hosts:', allowedHosts === true ? 'All hosts allowed' : allowedHosts);
7892
return config;
7993
})

0 commit comments

Comments
 (0)