| const express = require('express'); | |
| const https = require('https'); | |
| const fs = require('fs'); | |
| const { createProxyMiddleware } = require('http-proxy-middleware'); | |
| // const basicAuth = require('basic-auth-connect'); | |
| // SSL certificates | |
| const sslOptions = { | |
| key: fs.readFileSync('/etc/letsencrypt/live/aceadoorn.smartpickai.com/privkey.pem'), | |
| cert: fs.readFileSync('/etc/letsencrypt/live/aceadoorn.smartpickai.com/fullchain.pem') | |
| }; | |
| // const auth = basicAuth('ace', '2024=password=2024'); // Replace 'username' and 'password' with your credentials | |
| const app = express(); | |
| // Proxy middleware options | |
| const proxyOptions = { | |
| target: 'http://127.0.0.1:8888', // Target host | |
| changeOrigin: true, // needed for virtual hosted sites | |
| ws: true, // proxy w ebsockets | |
| onProxyReq: (proxyReq, req, res) => { | |
| // Add API Key to header | |
| proxyReq.setHeader('X-API-Key', 'xiCQTaoQKXUNATzuFLWRgtoJKiFXiDGvnk'); | |
| } | |
| }; | |
| // app.use(auth); | |
| // Apply proxy middleware for all incoming requests | |
| app.use('/', createProxyMiddleware(proxyOptions)); | |
| // Create HTTPS server with SSL options | |
| https.createServer(sslOptions, app).listen(8080, () => { | |
| console.log('HTTPS Server running on port 8080'); | |
| }); |