GitHub CoPilot Zertifikat

This commit is contained in:
chk
2026-06-08 19:08:13 +02:00
parent 71f227ace1
commit 90f60f9d5d
3 changed files with 61 additions and 11 deletions

19
https/cert_abcd.cer Normal file
View File

@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDGDCCAgCgAwIBAgIQIKm3TdMAErVIFuSUWmXD1TANBgkqhkiG9w0BAQsFADAU
MRIwEAYDVQQDDAlsb2NhbGhvc3QwHhcNMjIwNzI3MTMwMDUzWhcNMjMwNzI3MTMy
MDUzWjAUMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IB
DwAwggEKAoIBAQC97MG8XIuUGoAskplE0qhMv5VyZ2Sgkp4vv8yLVP63VBvYPpg9
hi6w8HTCwhBIy2ZmUrztqQ7Ye8fFaWlowDnrTp10ewAiAWvpjxSyeJE7dfP1AQcb
x3/YgrOCvQfy/5Xtcnm1SC/9VtxutcePJMwvD6S/5dpkVeCUhVpPuagEGvzStMhk
ovMxxaTcEG++N+2CiEtBpe4xxmDs0mmZhhJgO5t6roYLZzy2Q3BSJ3FNHArOOD3R
hxh0aV9c4RHQUGSZVVUfwUORGDp5XMqlJjfSsnNncBDBex4byV9SBOkQ4mxKQa/c
LG2MQ1RjLSVXSZ3QFMDgWdw+FWIapiOCoMXJAgMBAAGjZjBkMA4GA1UdDwEB/wQE
AwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwFAYDVR0RBA0wC4IJ
bG9jYWxob3N0MB0GA1UdDgQWBBSju5UGtw9Kz49/xVHoT0XnTlKtkDANBgkqhkiG
9w0BAQsFAAOCAQEAlEqbYXNgVTBLedFNOZz97IxrlAckG+4FMzcXIWhY55GvqwtL
gwWGrjKqGkXLhMVDzWHPSKWYxDdU6WJcBux9yuOz//s1Pro59jRIJvcOivbpXLPI
SaFPnc/29UeEDoh22AGr/9sAhOX2CrVMmrbaaDcZ8UN/YnT1bwufKFQipK1sGSR+
U5ISZ+pUXJ75aJFEZujucpFT1Sl6GWRWiL7u1Zacmm8jGIdZwpDIynSYK821fJMR
lVDQ9kPBBmU+Ummei/8vc+tqm2/3voekgLxIwxdpykn3L4JMtOn83+sZ2HVoS3Bz
/5+6Gc6u5+d3wLeO23q/sOARprC3ytzGc5bQRw==
-----END CERTIFICATE-----

4
https/info.txt Normal file
View File

@@ -0,0 +1,4 @@
abcd
SET OPENSSL_CONF="C:\Program Files (x86)\OpenSSL-Win32\bin\openssl.cfg"

View File

@@ -1,6 +1,8 @@
import express from 'express'; import express from 'express';
import https from 'https';
import path from 'path'; import path from 'path';
import fs from 'fs/promises'; import fs from 'fs';
import fsPromises from 'fs/promises';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import process from 'process'; import process from 'process';
@@ -15,6 +17,9 @@ const publicDir = path.join(__dirname, '..', 'public');
const snapshotsDir = path.join(publicDir, 'snapshots'); const snapshotsDir = path.join(publicDir, 'snapshots');
const WEBCAM_URL = process.env.WEBCAM_URL || ''; const WEBCAM_URL = process.env.WEBCAM_URL || '';
const BODYTRACKER_URL = process.env.BODYTRACKER_URL || ''; const BODYTRACKER_URL = process.env.BODYTRACKER_URL || '';
const HTTPS_KEY_PATH = process.env.HTTPS_KEY_PATH || path.join(__dirname, '..', 'https', 'localhost.key');
const HTTPS_CERT_PATH = process.env.HTTPS_CERT_PATH || path.join(__dirname, '..', 'https', 'localhost.pem');
const HTTPS_PASSPHRASE = process.env.HTTPS_PASSPHRASE || 'abcd';
app.use(express.static(publicDir)); app.use(express.static(publicDir));
@@ -23,13 +28,13 @@ app.get('/api/health', (req, res) => {
}); });
async function findLatestSnapshotFile() { async function findLatestSnapshotFile() {
const files = await fs.readdir(snapshotsDir); const files = await fsPromises.readdir(snapshotsDir);
const entries = await Promise.all( const entries = await Promise.all(
files files
.filter((name) => name.endsWith('.csv')) .filter((name) => name.endsWith('.csv'))
.map(async (name) => ({ .map(async (name) => ({
name, name,
mtime: (await fs.stat(path.join(snapshotsDir, name))).mtime.valueOf() mtime: (await fsPromises.stat(path.join(snapshotsDir, name))).mtime.valueOf()
})) }))
); );
if (entries.length === 0) return null; if (entries.length === 0) return null;
@@ -69,15 +74,15 @@ app.get('/api/latest-snapshot', async (req, res) => {
const imagePath = path.join(snapshotsDir, `${baseName}_annotated.jpg`); const imagePath = path.join(snapshotsDir, `${baseName}_annotated.jpg`);
const imagePath2 = path.join(snapshotsDir, `${baseName}_annotated2.jpg`); const imagePath2 = path.join(snapshotsDir, `${baseName}_annotated2.jpg`);
const content = await fs.readFile(csvPath, 'utf8'); const content = await fsPromises.readFile(csvPath, 'utf8');
const result = { filename: latestFile, mtime: (await fs.stat(csvPath)).mtime.toISOString(), content }; const result = { filename: latestFile, mtime: (await fsPromises.stat(csvPath)).mtime.toISOString(), content };
try { try {
result.jsonFile = { filename: `${baseName}.json`, content: await fs.readFile(jsonPath, 'utf8') }; result.jsonFile = { filename: `${baseName}.json`, content: await fsPromises.readFile(jsonPath, 'utf8') };
} catch {} } catch {}
try { try {
const jpg = await fs.readFile(imagePath); const jpg = await fsPromises.readFile(imagePath);
result.imageFile = { result.imageFile = {
filename: path.basename(imagePath), filename: path.basename(imagePath),
mimeType: 'image/jpeg', mimeType: 'image/jpeg',
@@ -86,7 +91,7 @@ app.get('/api/latest-snapshot', async (req, res) => {
} catch {} } catch {}
try { try {
const jpg2 = await fs.readFile(imagePath2); const jpg2 = await fsPromises.readFile(imagePath2);
result.image2 = { result.image2 = {
filename: path.basename(imagePath2), filename: path.basename(imagePath2),
mimeType: 'image/jpeg', mimeType: 'image/jpeg',
@@ -160,6 +165,24 @@ async function checkServiceReachability(name, url) {
} }
} }
async function createHttpsServer() {
try {
await fsPromises.access(HTTPS_KEY_PATH);
await fsPromises.access(HTTPS_CERT_PATH);
const key = fs.readFileSync(HTTPS_KEY_PATH);
const cert = fs.readFileSync(HTTPS_CERT_PATH);
const httpsOptions = { key, cert, passphrase: HTTPS_PASSPHRASE };
console.log(`HTTPS-Zertifikate geladen: ${HTTPS_KEY_PATH}, ${HTTPS_CERT_PATH}`);
return https.createServer(httpsOptions, app);
} catch (err) {
console.warn('HTTPS-Zertifikate konnten nicht geladen werden:', err.message || err);
console.warn('Fallback auf HTTP. External proxy muss HTTPS terminieren.');
return null;
}
}
async function startServer() { async function startServer() {
if (WEBCAM_URL) { if (WEBCAM_URL) {
await checkServiceReachability('WEBCAM_URL', new URL('/health', WEBCAM_URL).toString()); await checkServiceReachability('WEBCAM_URL', new URL('/health', WEBCAM_URL).toString());
@@ -169,8 +192,12 @@ async function startServer() {
await checkServiceReachability('BODYTRACKER_URL', new URL('/v1/health', BODYTRACKER_URL).toString()); await checkServiceReachability('BODYTRACKER_URL', new URL('/v1/health', BODYTRACKER_URL).toString());
} }
app.listen(PORT, () => { const server = await createHttpsServer();
console.log(`appRobotHoming backend listening on port ${PORT}`); const isHttps = Boolean(server);
const listenServer = server || app;
listenServer.listen(PORT, () => {
console.log(`appRobotHoming backend listening on port ${PORT} (${isHttps ? 'HTTPS' : 'HTTP'})`);
console.log(`WEBCAM_URL=${WEBCAM_URL || '<lokal>'}`); console.log(`WEBCAM_URL=${WEBCAM_URL || '<lokal>'}`);
console.log(`BODYTRACKER_URL=${BODYTRACKER_URL || '<nicht konfiguriert>'}`); console.log(`BODYTRACKER_URL=${BODYTRACKER_URL || '<nicht konfiguriert>'}`);
}); });
@@ -180,7 +207,7 @@ startServer().catch((err) => {
console.error('Fehler beim Starten des Servers:', err); console.error('Fehler beim Starten des Servers:', err);
console.log('Starte trotzdem den Server weiter...'); console.log('Starte trotzdem den Server weiter...');
app.listen(PORT, () => { app.listen(PORT, () => {
console.log(`appRobotHoming backend listening on port ${PORT}`); console.log(`appRobotHoming backend listening on port ${PORT} (HTTP)`);
console.log(`WEBCAM_URL=${WEBCAM_URL || '<lokal>'}`); console.log(`WEBCAM_URL=${WEBCAM_URL || '<lokal>'}`);
console.log(`BODYTRACKER_URL=${BODYTRACKER_URL || '<nicht konfiguriert>'}`); console.log(`BODYTRACKER_URL=${BODYTRACKER_URL || '<nicht konfiguriert>'}`);
}); });