service worker stuff

This commit is contained in:
ari melody 2023-09-30 08:25:29 +01:00
parent 1edc2efdec
commit f2d72f782e
Signed by: ari
GPG key ID: CF99829C92678188
2 changed files with 20 additions and 3 deletions

14
OpenTerminal.service Normal file
View file

@ -0,0 +1,14 @@
[Unit]
Description=OpenTerminal Server
After=network.target
[Service]
Environment="PORT=443"
Environment="SSL_CERT=/certs/arimelody.me/arimelody.me.crt"
Environment="SSL_KEY=/certs/arimelody.me/arimelody.me.key"
Type=simple
ExecStart=/usr/bin/npm run start
Restart=on-failure
[Install]
WantedBy=multi-user.target

View file

@ -4,8 +4,8 @@ const path = require('path');
const Websocket = require('ws');
const config = {
cert: fs.readFileSync('./certs/cert.crt'),
key: fs.readFileSync('./certs/cert.key'),
cert: fs.readFileSync(process.env.SSL_CERT || './certs/cert.crt'),
key: fs.readFileSync(process.env.SSL_KEY || './certs/cert.key'),
}
const MIME_TYPES = {
@ -39,6 +39,7 @@ made with <3 by ari melody
`;
const PORT = process.env.PORT || 8080;
let sockets = [];
let buffer = "";
@ -114,7 +115,9 @@ function handle_message(msg) {
*/
}
server.listen(8080);
server.listen(PORT, () => {
console.log(`OpenTerminal is now LIVE on https://127.0.0.1:${PORT}!`);
});
function send_text(text) {
sockets.forEach(s => s.send(text));