Skip to content

Commit e1550ef

Browse files
committed
Allow running vite dev server in https mode
1 parent 60faec6 commit e1550ef

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

.github/config/.env.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@ VAULT_URL=http://localhost:8200/v1
7878
VAULT_ROLE=swiftbrowserui
7979
VAULT_SECRET=swiftui
8080
VAULT_KEY_NAME=human-readable-short-string-to-identify-the-whitelisted-key
81+
82+
VITE_TLS=False
83+
# paths should be absolute or relative to vite.config.js
84+
VITE_TLS_CERT=
85+
VITE_TLS_KEY=

swift_browser_ui_frontend/vite.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@
22
import { defineConfig } from "vite";
33
import { createVuePlugin as vue } from "vite-plugin-vue2";
44

5+
import fs from "node:fs";
56
import path from "node:path";
67

8+
const TLS_ENABLED = process.env.VITE_TLS === "True";
9+
const http_mode = TLS_ENABLED ? "https" : "http";
10+
// paths should be absolute or relative to vite.config.js
11+
const TLS_CERT_PATH = process.env.VITE_TLS_CERT || undefined;
12+
const TLS_KEY_PATH = process.env.VITE_TLS_KEY || undefined;
13+
14+
let https = null;
15+
if (TLS_ENABLED) {
16+
console.log("vite dev serve will expect https");
17+
https = {
18+
key: fs.readFileSync(TLS_KEY_PATH),
19+
cert: fs.readFileSync(TLS_CERT_PATH),
20+
};
21+
}
22+
723
const proxyTo = {
8-
target: `http://${process.env.BACKEND_HOST || "localhost"}:${process.env.BACKEND_PORT || "8080"}`,
24+
target: `${http_mode}://${process.env.BACKEND_HOST || "localhost"}:${process.env.BACKEND_PORT || "8080"}`,
925
changeOrigin: true,
1026
secure: false, // Won't check certificates
1127
};
@@ -101,6 +117,7 @@ export default defineConfig(({ command, mode }) => {
101117
server: {
102118
host: "0.0.0.0",
103119
port: process.env.FRONTEND_PORT || "8081",
120+
https,
104121
strictPort: true,
105122
proxy: {
106123
"/static/assets": proxyTo,

0 commit comments

Comments
 (0)