Skip to content

Commit 9992497

Browse files
committed
implements https
1 parent d728dc4 commit 9992497

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.nuxt/
44
.nitro/
55
.cache/
6+
certificates/
67
dist/
78
node_modules/
89
.DS_Store/

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ APPNAME?=sesame-app-manager
44
APP_PORT?=3002
55
PLATFORM?=linux/amd64
66

7+
CERT_DIR = ./certificates
8+
COMMON_NAME = localhost
9+
DAYS_VALID = 365
10+
11+
$(shell mkdir -p $(CERT_DIR))
12+
713
.DEFAULT_GOAL := help
814
help:
915
@printf "\033[33mUsage:\033[0m\n make [target] [arg=\"val\"...]\n\n\033[33mTargets:\033[0m\n"
@@ -49,3 +55,23 @@ exec:
4955
-e NODE_ENV=development \
5056
-v $(CURDIR):/data \
5157
$(IMGNAME) bash
58+
59+
generate-ssl-cert: ## Générer les certificats HTTPS auto-signés
60+
@echo "Génération des certificats HTTPS auto-signés..."
61+
@openssl req -x509 \
62+
-newkey rsa:4096 \
63+
-keyout $(CERT_DIR)/server.key \
64+
-out $(CERT_DIR)/server.crt \
65+
-days $(DAYS_VALID) \
66+
-nodes \
67+
-subj "/CN=$(COMMON_NAME)"
68+
@chmod 600 $(CERT_DIR)/server.key
69+
@chmod 644 $(CERT_DIR)/server.crt
70+
@echo "Certificats générés avec succès dans $(CERT_DIR)"
71+
72+
clean-ssl-cert: ## Nettoyer les certificats HTTPS
73+
@rm -rf $(CERT_DIR)
74+
@echo "Certificats supprimés"
75+
76+
show-cert-info: ## Afficher les informations du certificat
77+
@openssl x509 -in $(CERT_DIR)/server.crt -text -noout

nuxt.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import pugPlugin from 'vite-plugin-pug'
44
import openapiTS from 'openapi-typescript'
55
import { defineNuxtConfig } from 'nuxt/config'
66
import { parse } from 'yaml'
7+
import consola from 'consola'
78

89
const SESAME_APP_API_URL = process.env.SESAME_APP_API_URL || 'http://localhost:4002'
910

@@ -16,6 +17,19 @@ if (process.env.SESAME_APP_DARK_MODE) {
1617
}
1718
}
1819

20+
let https = {}
21+
if (/yes|1|on|true/i.test(`${process.env.SESAME_HTTPS_ENABLED}`)) {
22+
try {
23+
https = {
24+
key: readFileSync(`${process.env.SESAME_HTTPS_PATH_KEY}`, 'utf8'),
25+
cert: readFileSync(`${process.env.SESAME_HTTPS_PATH_CERT}`, 'utf8'),
26+
};
27+
consola.info('[Nuxt] SSL certificates loaded successfully')
28+
} catch (error) {
29+
consola.warn('[Nuxt] Error while reading SSL certificates', error)
30+
}
31+
}
32+
1933
// https://nuxt.com/docs/api/configuration/nuxt-config
2034
export default defineNuxtConfig({
2135
ssr: false,
@@ -25,6 +39,7 @@ export default defineNuxtConfig({
2539
debug: !!process.env.DEBUG,
2640
devServer: {
2741
port: 3000,
42+
https,
2843
},
2944
devtools: {
3045
enabled: process.env.NODE_ENV === 'development',

start.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ function buildNuxt() {
5151
}
5252

5353
;(async () => {
54+
if (/yes|1|on|true/i.test(`${process.env.SESAME_HTTPS_ENABLED}`)) {
55+
try {
56+
process.env.NITRO_SSL_KEY = readFileSync(`${process.env.SESAME_HTTPS_PATH_KEY}`, 'utf8')
57+
process.env.NITRO_SSL_CERT = readFileSync(`${process.env.SESAME_HTTPS_PATH_CERT}`, 'utf8')
58+
consola.info('[Nuxt] SSL certificates loaded successfully')
59+
} catch (error) {
60+
consola.warn('[Nuxt] Error while reading SSL certificates', error)
61+
}
62+
}
63+
5464
if (hashEnv() !== readHash()) {
5565
consola.warn('Hash changed, rebuilding...')
5666
consola.info(`Hash: ${hashEnv()}, Previous: ${readHash()}`)

0 commit comments

Comments
 (0)