support http and https

This commit is contained in:
Sebastian 2023-03-10 01:21:28 -03:00
parent 034f2c6dcb
commit 0fb6c098d7
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069
2 changed files with 7 additions and 2 deletions

View File

@ -1,7 +1,8 @@
/* eslint-disable no-undef */
function setupLiveReload(): void {
const ws = new WebSocket("wss://localhost:8080/ws");
const protocol = window.location.protocol === "http:" ? "ws:" : "wss:";
const ws = new WebSocket(`${protocol}://localhost:8080/ws`);
ws.addEventListener("message", (message) => {
try {

View File

@ -2,6 +2,7 @@ import { Logger } from "@gnu-taler/taler-util";
import chokidar from "chokidar";
import express from "express";
import https from "https";
import http from "http";
import { parse } from "url";
import WebSocket from "ws";
@ -30,6 +31,7 @@ export async function serve(opts: {
port: number;
source?: string;
development?: boolean;
insecure?: boolean;
examplesLocationJs?: string;
examplesLocationCss?: string;
onUpdate?: () => Promise<void>;
@ -37,7 +39,9 @@ export async function serve(opts: {
const app = express();
app.use(PATHS.APP, express.static(opts.folder));
const server = https.createServer(httpServerOptions, app);
const server = opts.insecure
? http.createServer(app)
: https.createServer(httpServerOptions, app);
logger.info(`serving ${opts.folder} on ${opts.port}`);
logger.info(` ${PATHS.APP}: application`);
logger.info(` ${PATHS.EXAMPLE}: examples`);