Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vite): add HTTPS support with configurable SSL #8585

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/twenty-front/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ GENERATE_SOURCEMAP=false
# REACT_APP_PORT=3001
# CHROMATIC_PROJECT_TOKEN=
# VITE_DISABLE_TYPESCRIPT_CHECKER=true
# VITE_DISABLE_ESLINT_CHECKER=true
# VITE_DISABLE_ESLINT_CHECKER=true
# VITE_ENABLE_SSL=false
# SSL_KEY_PATH="./certs/your-cert.key"
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved
# SSL_CERT_PATH="./certs/your-cert.crt"
20 changes: 18 additions & 2 deletions packages/twenty-front/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isNonEmptyString } from '@sniptt/guards';
import react from '@vitejs/plugin-react-swc';
import wyw from '@wyw-in-js/vite';
import path from 'path';
import fs from 'fs';
import { defineConfig, loadEnv, searchForWorkspaceRoot } from 'vite';
import checker from 'vite-plugin-checker';
import svgr from 'vite-plugin-svgr';
Expand All @@ -18,6 +19,7 @@ export default defineConfig(({ command, mode }) => {
VITE_BUILD_SOURCEMAP,
VITE_DISABLE_TYPESCRIPT_CHECKER,
VITE_DISABLE_ESLINT_CHECKER,
VITE_ENABLE_SSL,
REACT_APP_PORT,
} = env;

Expand Down Expand Up @@ -62,13 +64,27 @@ export default defineConfig(({ command, mode }) => {
};
}

if (VITE_ENABLE_SSL && (!env.SSL_KEY_PATH || !env.SSL_CERT_PATH)) {
throw new Error(
'to use https SSL_KEY_PATH and SSL_CERT_PATH must be both defined',
);
}

return {
root: __dirname,
cacheDir: '../../node_modules/.vite/packages/twenty-front',

server: {
port,
host: 'localhost',
port: port,
protocol: VITE_ENABLE_SSL ? 'https' : 'http',
...(VITE_ENABLE_SSL
? {
https: {
key: fs.readFileSync(env.SSL_KEY_PATH),
cert: fs.readFileSync(env.SSL_CERT_PATH),
},
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved
}
: {}),
fs: {
allow: [
searchForWorkspaceRoot(process.cwd()),
Expand Down
Loading