Add support for SSL in development (#5668)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import { optimizeLodashImports } from "@optimize-lodash/rollup-plugin";
|
||||
@@ -5,7 +6,7 @@ import react from "@vitejs/plugin-react";
|
||||
import browserslistToEsbuild from "browserslist-to-esbuild";
|
||||
import dotenv from "dotenv";
|
||||
import { webpackStats } from "rollup-plugin-webpack-stats";
|
||||
import { defineConfig } from "vite";
|
||||
import { CommonServerOptions, defineConfig } from "vite";
|
||||
import { VitePWA } from "vite-plugin-pwa";
|
||||
import { viteStaticCopy } from "vite-plugin-static-copy";
|
||||
|
||||
@@ -14,6 +15,20 @@ dotenv.config({
|
||||
silent: true,
|
||||
});
|
||||
|
||||
let httpsConfig: CommonServerOptions["https"] | undefined;
|
||||
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
try {
|
||||
httpsConfig = {
|
||||
key: fs.readFileSync("./server/config/certs/private.key"),
|
||||
cert: fs.readFileSync("./server/config/certs/public.cert"),
|
||||
};
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn("No local SSL certs found, HTTPS will not be available");
|
||||
}
|
||||
}
|
||||
|
||||
export default () =>
|
||||
defineConfig({
|
||||
root: "./",
|
||||
@@ -22,6 +37,7 @@ export default () =>
|
||||
server: {
|
||||
port: 3001,
|
||||
host: true,
|
||||
https: httpsConfig,
|
||||
},
|
||||
plugins: [
|
||||
// https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme
|
||||
|
||||
Reference in New Issue
Block a user