Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ dev-server: node_modules/.installed build-main ## Start server mode with hot rel
@# On Windows, use npm run because bunx doesn't correctly pass arguments
@npmx concurrently -k \
"npmx nodemon --watch src --watch tsconfig.main.json --watch tsconfig.json --ext ts,tsx,json --ignore dist --ignore node_modules --exec node scripts/build-main-watch.js" \
"npmx nodemon --watch dist/main.js --watch dist/main-server.js --delay 500ms --exec \"node dist/main.js server --host $(or $(BACKEND_HOST),localhost) --port $(or $(BACKEND_PORT),3000)\"" \
"npmx nodemon --watch dist/cli/index.js --watch dist/cli/server.js --delay 500ms --exec \"node dist/cli/index.js server --host $(or $(BACKEND_HOST),localhost) --port $(or $(BACKEND_PORT),3000)\"" \
"$(SHELL) -lc \"MUX_VITE_HOST=$(or $(VITE_HOST),127.0.0.1) MUX_VITE_PORT=$(or $(VITE_PORT),5173) VITE_BACKEND_URL=http://$(or $(BACKEND_HOST),localhost):$(or $(BACKEND_PORT),3000) vite\""
else
dev-server: node_modules/.installed build-main ## Start server mode with hot reload (backend :3000 + frontend :5173). Use VITE_HOST=0.0.0.0 BACKEND_HOST=0.0.0.0 for remote access
Expand All @@ -145,7 +145,7 @@ dev-server: node_modules/.installed build-main ## Start server mode with hot rel
@echo "For remote access: make dev-server VITE_HOST=0.0.0.0 BACKEND_HOST=0.0.0.0"
@bun x concurrently -k \
"bun x concurrently \"$(TSGO) -w -p tsconfig.main.json\" \"bun x tsc-alias -w -p tsconfig.main.json\"" \
"bun x nodemon --watch dist/main.js --watch dist/main-server.js --delay 500ms --exec 'NODE_ENV=development node dist/main.js server --host $(or $(BACKEND_HOST),localhost) --port $(or $(BACKEND_PORT),3000)'" \
"bun x nodemon --watch dist/cli/index.js --watch dist/cli/server.js --delay 500ms --exec 'NODE_ENV=development node dist/cli/index.js server --host $(or $(BACKEND_HOST),localhost) --port $(or $(BACKEND_PORT),3000)'" \
"MUX_VITE_HOST=$(or $(VITE_HOST),127.0.0.1) MUX_VITE_PORT=$(or $(VITE_PORT),5173) VITE_BACKEND_URL=http://$(or $(BACKEND_HOST),localhost):$(or $(BACKEND_PORT),3000) vite"
endif

Expand Down
13 changes: 11 additions & 2 deletions src/browser/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ import { IPC_CHANNELS, getChatChannel } from "@/common/constants/ipc-constants";
import type { IPCApi } from "@/common/types/ipc";

// Backend URL - defaults to same origin, but can be overridden via VITE_BACKEND_URL
// This allows frontend (Vite :8080) to connect to backend (:3000) in dev mode
const API_BASE = import.meta.env.VITE_BACKEND_URL ?? window.location.origin;
// This allows frontend (Vite :5173) to connect to backend (:3000) in dev mode
let API_BASE = import.meta.env.VITE_BACKEND_URL ?? window.location.origin;

// Fix 0.0.0.0 addresses (server bind address) to use actual client hostname
// 0.0.0.0 is not a valid client target - replace with window.location.hostname
if (API_BASE.includes("://0.0.0.0:")) {
const port = API_BASE.split(":").pop();
const protocol = API_BASE.startsWith("https") ? "https" : "http";
API_BASE = `${protocol}://${window.location.hostname}:${port}`;
}

const WS_BASE = API_BASE.replace("http://", "ws://").replace("https://", "wss://");

interface InvokeResponse<T> {
Expand Down
11 changes: 7 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const devServerHost = process.env.MUX_VITE_HOST ?? "127.0.0.1"; // Secure by def
const devServerPort = Number(process.env.MUX_VITE_PORT ?? "5173");
const previewPort = Number(process.env.MUX_VITE_PREVIEW_PORT ?? "4173");

// Allow localhost, 127.0.0.1, and all *.coder domains
// When host is 0.0.0.0, use undefined to allow all hosts (Vite's default for wildcard bind)
const allowedHosts = devServerHost === "0.0.0.0" ? undefined : ["localhost", "127.0.0.1", ".coder"];

const alias: Record<string, string> = {
"@": path.resolve(__dirname, "./src"),
};
Expand Down Expand Up @@ -89,7 +93,7 @@ export default defineConfig(({ mode }) => ({
host: devServerHost, // Configurable via MUX_VITE_HOST (defaults to 127.0.0.1 for security)
port: devServerPort,
strictPort: true,
allowedHosts: devServerHost === "0.0.0.0" ? undefined : ["localhost", "127.0.0.1"],
allowedHosts,
sourcemapIgnoreList: () => false, // Show all sources in DevTools

watch: {
Expand All @@ -116,8 +120,7 @@ export default defineConfig(({ mode }) => ({
pollInterval: 100
}
})
},

},
hmr: {
// Configure HMR to use the correct host for remote access
host: devServerHost,
Expand All @@ -129,7 +132,7 @@ export default defineConfig(({ mode }) => ({
host: "127.0.0.1",
port: previewPort,
strictPort: true,
allowedHosts: ["localhost", "127.0.0.1"],
allowedHosts: ["localhost", "127.0.0.1", ".coder"],
},
optimizeDeps: {
esbuildOptions: {
Expand Down
Loading