diff --git a/README.md b/README.md index e33e901e7e..a76fc8ea87 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,12 @@ Create a `.env` file in the root of the project directory and add the necessary - Description: Used for running E2E tests when authentication is enabled on the backend. This JWT token allows the test runner to authenticate and access the application during testing. - Example: TESTS_JWT_AUTH_TOKEN=your_jwt_auth_token_for_e2e_tests +`VITE_DISABLE_MKCERT_SSL` + +- Default: None (SSL certificates are enabled by default) +- Description: When set to "true", disables automatic SSL certificate generation via mkcert. This forces the development server to use HTTP instead of HTTPS and restricts SSL certificates to localhost only. +- Example: VITE_DISABLE_MKCERT_SSL=true + **Note:** These environment variables are optional. The application will use default values or fall back to certain behaviors if these variables are not set. However, setting them allows for greater customization and functionality, especially in different deployment environments or when running tests. ### Running the Project 🏃 diff --git a/mkcert.util.ts b/mkcert.util.ts new file mode 100644 index 0000000000..e231233823 --- /dev/null +++ b/mkcert.util.ts @@ -0,0 +1,11 @@ +import { MkcertPluginOptions } from "vite-plugin-mkcert"; + +export const securedDomainConfigured = process.env.VITE_APP_DOMAIN && process.env.VITE_ENABLE_MKCERT_SSL; + +export const securedDomainHosts = securedDomainConfigured + ? ["localhost", process.env.VITE_APP_DOMAIN].filter(Boolean) + : ["localhost"]; + +export const mkcertConfig: MkcertPluginOptions = { + hosts: securedDomainHosts as string[], +}; diff --git a/tsconfig.node.json b/tsconfig.node.json index 1fd88fdaa2..bb1e5f09b1 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -4,8 +4,8 @@ "skipLibCheck": true, "module": "ESNext", "moduleResolution": "bundler", - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "strict": true }, - "include": ["vite.config.ts", - "fixReactVirtualized.ts"] + "include": ["vite.config.ts","fixReactVirtualized.ts","mkcert.util.ts"] } diff --git a/vite.config.ts b/vite.config.ts index e084f27f18..385c7dd986 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -9,6 +9,7 @@ import { viteStaticCopy } from "vite-plugin-static-copy"; import svgr from "vite-plugin-svgr"; import { reactVirtualized } from "./fixReactVirtualized"; +import { securedDomainConfigured, mkcertConfig } from "./mkcert.util"; dotenv.config(); @@ -86,8 +87,8 @@ export default defineConfig({ include: ["tailwind-config", "apexcharts"], }, plugins: [ - ...(process.env.VITE_LOCAL_SSL_CERT === "true" ? [mkcert()] : []), react(), + ...(securedDomainConfigured ? [mkcert(mkcertConfig)] : []), ViteEjsPlugin((viteConfig) => ({ env: viteConfig.env, })), @@ -177,7 +178,7 @@ export default defineConfig({ }, }, server: { - host: process.env.VITE_APP_DOMAIN ? JSON.stringify(process.env.VITE_APP_DOMAIN) : true, + host: process.env.VITE_APP_DOMAIN ? "0.0.0.0" : true, port: process.env.VITE_LOCAL_PORT ? Number(process.env.VITE_LOCAL_PORT) : 8000, strictPort: true, },