Browse Source

Déplacement fichiers html + update server.js/py

master
scayac 3 months ago
parent
commit
fcb1797c86
  1. 1
      .gitignore
  2. 0
      html/index.html
  3. 6
      server.js
  4. 25
      server.py

1
.gitignore vendored

@ -1,3 +1,4 @@
.pio .pio
.vscode .vscode
.git .git
*.pem

0
index.html → html/index.html

6
server.js

@ -44,9 +44,9 @@ async function startServer() {
}; };
const server = https.createServer(options, (req, res) => { const server = https.createServer(options, (req, res) => {
let filePath = '.' + req.url; let filePath = './html' + req.url;
if (filePath === './') { if (filePath === './html/') {
filePath = './index.html'; filePath = './html/index.html';
} }
const extname = String(path.extname(filePath)).toLowerCase(); const extname = String(path.extname(filePath)).toLowerCase();

25
server.py

@ -14,12 +14,9 @@ PORT = 8443
def generate_certificate(): def generate_certificate():
"""Génère un certificat auto-signé si nécessaire""" """Génère un certificat auto-signé si nécessaire"""
cert_file = 'cert.pem' script_dir = os.path.dirname(os.path.abspath(__file__))
key_file = 'key.pem' cert_file = os.path.join(script_dir, 'cert.pem')
key_file = os.path.join(script_dir, 'key.pem')
if os.path.exists(cert_file) and os.path.exists(key_file):
print('✓ Certificats existants trouvés')
return cert_file, key_file
print('Génération d\'un certificat auto-signé...') print('Génération d\'un certificat auto-signé...')
try: try:
@ -38,10 +35,20 @@ def generate_certificate():
def main(): def main():
try: try:
cert_file, key_file = generate_certificate() # Les certificats sont à la racine du projet
cert_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cert.pem')
key_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'key.pem')
# Générer si nécessaire
if not os.path.exists(cert_file) or not os.path.exists(key_file):
generate_certificate()
else:
print('✓ Certificats existants trouvés')
# Changer vers le répertoire du script # Changer vers le répertoire html
os.chdir(os.path.dirname(os.path.abspath(__file__))) script_dir = os.path.dirname(os.path.abspath(__file__))
html_dir = os.path.join(script_dir, 'html')
os.chdir(html_dir)
# Créer le serveur HTTP # Créer le serveur HTTP
handler = http.server.SimpleHTTPRequestHandler handler = http.server.SimpleHTTPRequestHandler

Loading…
Cancel
Save