From e7556e1acfc5c54379e54a91b950030145a2c2f5 Mon Sep 17 00:00:00 2001 From: Frederik Rothenberger Date: Thu, 26 Oct 2023 14:54:31 +0200 Subject: [PATCH] Add option to run dev server using TLS This PR introduces the env variable `TLS_DEV_SERVER` that can be set to `1` to enable the dev server serving content using tls. --- package-lock.json | 20 ++++++++++++++++++++ package.json | 1 + vite.config.ts | 3 +++ 3 files changed, 24 insertions(+) diff --git a/package-lock.json b/package-lock.json index 9f16d51323..30ba27ea97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,7 @@ "@types/ua-parser-js": "^0.7.36", "@typescript-eslint/eslint-plugin": "6.7.5", "@typescript-eslint/parser": "6.7.5", + "@vitejs/plugin-basic-ssl": "^1.0.1", "@wdio/globals": "^8.6.9", "astro": "^2.4.1", "eslint": "8.51.0", @@ -2053,6 +2054,18 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@vitejs/plugin-basic-ssl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-basic-ssl/-/plugin-basic-ssl-1.0.1.tgz", + "integrity": "sha512-pcub+YbFtFhaGRTo1832FQHQSHvMrlb43974e2eS8EKleR3p1cDdkJFPci1UhwkEf1J9Bz+wKBSzqpKp7nNj2A==", + "dev": true, + "engines": { + "node": ">=14.6.0" + }, + "peerDependencies": { + "vite": "^3.0.0 || ^4.0.0" + } + }, "node_modules/@vitest/expect": { "version": "0.31.0", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-0.31.0.tgz", @@ -13463,6 +13476,13 @@ "eslint-visitor-keys": "^3.4.1" } }, + "@vitejs/plugin-basic-ssl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-basic-ssl/-/plugin-basic-ssl-1.0.1.tgz", + "integrity": "sha512-pcub+YbFtFhaGRTo1832FQHQSHvMrlb43974e2eS8EKleR3p1cDdkJFPci1UhwkEf1J9Bz+wKBSzqpKp7nNj2A==", + "dev": true, + "requires": {} + }, "@vitest/expect": { "version": "0.31.0", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-0.31.0.tgz", diff --git a/package.json b/package.json index bb71982cd1..24b075e2ab 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@types/ua-parser-js": "^0.7.36", "@typescript-eslint/eslint-plugin": "6.7.5", "@typescript-eslint/parser": "6.7.5", + "@vitejs/plugin-basic-ssl": "^1.0.1", "@wdio/globals": "^8.6.9", "astro": "^2.4.1", "eslint": "8.51.0", diff --git a/vite.config.ts b/vite.config.ts index 8c1183dd60..7300fcf70b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,3 +1,4 @@ +import basicSsl from "@vitejs/plugin-basic-ssl"; import { resolve } from "path"; import { AliasOptions, defineConfig, UserConfig } from "vite"; import { @@ -58,6 +59,7 @@ export default defineConfig(({ mode }: UserConfig): UserConfig => { plugins: [ [...(mode === "development" ? [injectCanisterIdPlugin()] : [])], [...(mode === "production" ? [minifyHTML(), compression()] : [])], + [...(process.env.TLS_DEV_SERVER === "1" ? [basicSsl()] : [])], ], optimizeDeps: { esbuildOptions: { @@ -67,6 +69,7 @@ export default defineConfig(({ mode }: UserConfig): UserConfig => { }, }, server: { + https: process.env.TLS_DEV_SERVER === "1", proxy: { "/api": "http://127.0.0.1:4943", },