Commit 7d05f584 authored by Grant's avatar Grant
Browse files

[dev] vite dev server proxies /api routes (simplify development)

parent 465b63e4
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -46,14 +46,11 @@ type SentEventValue<K extends keyof INetworkEvents> = EventEmitter.ArgumentMap<
>[Extract<K, keyof INetworkEvents>];

class Network extends EventEmitter<INetworkEvents> {
  socket: Socket<ServerToClientEvents, ClientToServerEvents> = io(
    import.meta.env.VITE_API_HOST,
    {
  socket: Socket<ServerToClientEvents, ClientToServerEvents> = io("", {
    autoConnect: false,
    withCredentials: true,
    reconnection: true,
    }
  );
  });
  private online_count = 0;
  private stateEvents: {
    [key in keyof INetworkEvents]?: SentEventValue<key>;
+1 −3
Original line number Diff line number Diff line
@@ -40,9 +40,7 @@ export const api = async <T = unknown, Error = string>(
  status: number;
  data: ({ success: true } & T) | { success: false; error: Error };
}> => {
  const API_HOST = import.meta.env.VITE_API_HOST || "";

  const req = await fetch(API_HOST + endpoint, {
  const req = await fetch(endpoint, {
    method,
    credentials: "include",
    headers: {
+9 −0
Original line number Diff line number Diff line
@@ -23,4 +23,13 @@ export default defineConfig({
  define: {
    __COMMIT_HASH__: JSON.stringify(commitHash),
  },
  server: {
    proxy: {
      "/api": "http://localhost:3000",
      "/socket.io": {
        target: "ws://localhost:3000",
        ws: true,
      },
    },
  },
});