mobin-dev-vite-proxy
v0.1.2
Published
Development-only Vite proxy for Mobin APIs, SSO and local backend cookies.
Maintainers
Readme
mobin-dev-vite-proxy
Typed Vite development proxy for APIs, SSO pages and backend cookies. Build and preview are excluded. Legacy localhost checks in proxied JavaScript are adapted automatically to keep SSO API requests on the local origin.
Install and use
npm install --save-dev mobin-dev-vite-proxyimport { defineConfig } from "vite";
import mobinDevViteProxy, { type MobinDevViteProxyOptions } from "mobin-dev-vite-proxy";
const options: MobinDevViteProxyOptions = {
baseUrl: "https://example.com",
};
export default defineConfig({
plugins: [mobinDevViteProxy(options)],
});Request /api/... and visit /sso/... on the Vite origin. The plugin forwards them
to baseUrl. A lazy baseUrl: () => selectedBackend is also supported and is
evaluated when the development server starts. Restart dev after changing it.
Cookies
Every Set-Cookie header is processed, regardless of its cookie name. The plugin
removes Domain, so the browser stores the cookie on the local host. Cookie paths
are preserved, with any baseUrl path prefix removed. Same-name cookies with
different paths stay distinct. HttpOnly, Expires and Max-Age are preserved,
including cookie deletion.
For HTTP dev servers, Secure and Partitioned are removed and SameSite=None
becomes SameSite=Lax. HTTPS dev servers preserve those attributes. An absent
SameSite defaults to Lax locally. Existing Strict and Lax values are preserved.
Secure-prefixed cookies such as __Secure- and __Host- require local HTTPS under
the browser's cookie rules. Cookie names are preserved.
Cookies are received only from responses passing through this proxy. Open the SSO
on the local /sso URL to log in. JavaScript cannot read cookies marked HttpOnly.
The application must use backend cookie authentication. Browser storage limits and
invalid backend cookie values still apply.
Options
| Option | Default | Purpose |
| ------------ | ------------------ | -------------------------------------- |
| baseUrl | Required | Backend URL or a function returning it |
| proxyPaths | ["/api", "/sso"] | Local path prefixes to forward |
Existing unrelated Vite proxy routes are preserved. Redirects to the backend are rewritten to the local origin. Redirects to external identity providers are preserved. The development server's port, host and TLS settings remain application settings.
Develop and publish
The package ships native ESM and TypeScript declarations, with no build step or runtime dependencies. Node.js 20+ is required. Integration tests use Vite 8; Vite 5.4 compatibility was verified for the preceding release.
npm install
npm test
npm pack --dry-run
npm publishFor this application's local installation, run npm install --save-dev ./mobin-dev-vite-proxy
from the application root. After publishing, replace that dependency with
npm install --save-dev [email protected].
The initial license is UNLICENSED. Select the intended license before public distribution.
The automatic adapter replaces exact quoted localhost hostnames in proxied JavaScript. It supports the current SSO hostname checks, including string tables. The application must still use the incoming origin when choosing its API URL.
Supported Vite versions: 5.4.20 through 8.x. Vite 8 requires Node.js 20.19+ or 22.12+.
