Some basic scripts to start building projects with Vite:

  • Plain JS: mkdir my-app and npm init vite@latest Alternatively: bun create vite <app-name> then select the app you want to build.

Then, go ahead and npm installand viteto start the dev-server. (Or bun install)

Vite is based on esbuilt wich is written inGo

Settings

Proxy

The proxy setting in Vite allows you to redirect certain HTTP requests from your development server to another server. This is particularly useful when your frontend (running on the Vite dev server) needs to communicate with a backend server running on a different port or domain.

For solving CORS Issues: This setup effectively bypasses CORS restrictions because, from the browser’s perspective, the request is being made to the same origin (your Vite server). The actual forwarding to a different server happens server-side.

e. g. this can be used to make a WS request from localhost:5173, to be in fact from

server: {
  proxy: {
    '/ws': {
      target: 'ws://localhost:3000',
      ws: true,
    },
  },
}
  • Any request from your frontend to a path starting with /ws (including WebSocket connections) will be proxied.
  • These requests are forwarded to ws://localhost:3000.
  • Your frontend code can connect to ws://localhost:5173/ws (Vite’s server), but the actual connection will be established with your Go server on port 3000.