https and ssl integration on the backend, frontend and started integration of logistics app as a separate frontend

This commit is contained in:
GotthardG
2024-11-19 09:56:05 +01:00
parent a91d74b718
commit a931bfb8ec
14 changed files with 264 additions and 267 deletions

View File

@ -1,14 +1,16 @@
// fetch-and-generate-openapi.js
import fs from 'fs';
import http from 'http';
import https from 'https'; // Use https instead of http
import { exec } from 'child_process';
import chokidar from 'chokidar';
import path from 'path';
import util from 'util';
const OPENAPI_URL = 'http://127.0.0.1:8000/openapi.json';
const OPENAPI_URL = 'https://127.0.0.1:8000/openapi.json';
const SCHEMA_PATH = path.resolve('./src/openapi.json');
const OUTPUT_DIRECTORY = path.resolve('./openapi');
const SSL_KEY_PATH = path.resolve('../backend/ssl/key.pem'); // Path to SSL key
const SSL_CERT_PATH = path.resolve('../backend/ssl/cert.pem'); // Path to SSL certificate
console.log(`Using SCHEMA_PATH: ${SCHEMA_PATH}`);
console.log(`Using OUTPUT_DIRECTORY: ${OUTPUT_DIRECTORY}`);
@ -38,8 +40,14 @@ async function fetchAndGenerate() {
console.log("🚀 Fetching OpenAPI schema...");
try {
const options = {
rejectUnauthorized: false,
key: fs.readFileSync(SSL_KEY_PATH),
cert: fs.readFileSync(SSL_CERT_PATH),
};
const res = await new Promise((resolve, reject) => {
http.get(OPENAPI_URL, resolve).on('error', reject);
https.get(OPENAPI_URL, options, resolve).on('error', reject);
});
let data = '';
@ -97,7 +105,7 @@ const watcher = chokidar.watch(backendDirectory, { persistent: true, ignored: [S
watcher
.on('add', debounce(fetchAndGenerate, debounceDelay))
.on('change', debounce(fetchAndGenerate, debounceDelay))
.on('change', debounce(fetchAndGenerate, debounceDelay)) // Corrected typo here
.on('unlink', debounce(fetchAndGenerate, debounceDelay));
console.log(`👀 Watching for changes in ${backendDirectory}`);