Commit 7a1031f4d3dbd2c1cf4ca8a0054447b2e88c2e3b

Authored by ww
1 parent c15bd7d4

chore: add "VITE_CONTENT_SECURITY_POLICY" configure feild to usage switch http or https protocol

... ... @@ -35,3 +35,6 @@ VITE_GLOB_API_URL_PREFIX=/yt
35 35 #configuration
36 36 VITE_GLOB_CONFIGURATION = /thingskit-drawio
37 37
  38 +# Content Security Policy
  39 +VITE_CONTENT_SECURITY_POLICY = true
  40 +
... ...
... ... @@ -43,3 +43,5 @@ VITE_WEB_SOCKET = wss://dev.thingskit.com/api/ws/plugins/telemetry?token=
43 43 #configuration
44 44 VITE_GLOB_CONFIGURATION = http://localhost:3000
45 45
  46 +# Content Security Policy
  47 +VITE_CONTENT_SECURITY_POLICY = true
... ...
... ... @@ -10,7 +10,7 @@ import pkg from '../../../package.json';
10 10 import { GLOB_CONFIG_FILE_NAME } from '../../constant';
11 11
12 12 export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
13   - const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
  13 + const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH, VITE_CONTENT_SECURITY_POLICY } = env;
14 14
15 15 const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`;
16 16
... ... @@ -24,6 +24,9 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
24 24 // Inject data into ejs template
25 25 injectData: {
26 26 title: VITE_GLOB_APP_TITLE,
  27 + contentSecurityPolicy: VITE_CONTENT_SECURITY_POLICY
  28 + ? `<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />`
  29 + : '',
27 30 },
28 31 // Embed the generated app.config.js file
29 32 tags: isBuild
... ...
1 1 <!DOCTYPE html>
2 2 <html lang="en" id="htmlRoot">
3 3 <head>
4   - <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />
  4 + <%- contentSecurityPolicy %>
5 5 <meta charset="UTF-8" />
6 6 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
7 7 <meta name="renderer" content="webkit" />
... ...
... ... @@ -71,6 +71,7 @@ declare global {
71 71 VITE_LEGACY: boolean;
72 72 VITE_USE_IMAGEMIN: boolean;
73 73 VITE_GENERATE_UI: string;
  74 + VITE_CONTENT_SECURITY_POLICY: boolean;
74 75 }
75 76
76 77 declare function parseInt(s: string | number, radix?: number): number;
... ...