File size: 931 Bytes
3a76a4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const express = require('express');
const https = require('https');
const fs = require('fs');
const app = express();

const host = '0.0.0.0';
const port = 8080;

// Path to your certificate and key files
const privateKey = fs.readFileSync('key.pem', 'utf8');
const certificate = fs.readFileSync('cert.pem', 'utf8');

const credentials = { key: privateKey, cert: certificate };

// Middleware to set required headers for SharedArrayBuffer access
app.use((req, res, next) => {
  res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
  res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
  next();
});

// Serve static files from the 'public' directory
app.use(express.static('.'));

// Create an HTTPS server with your custom certificate and key
const httpsServer = https.createServer(credentials, app);

httpsServer.listen(port, host, () => {
  console.log(`HTTPS server listening at https://${host}:${port}`);
});