commit 0fb6c098d78de77d100ef405585040118aa61312
parent 034f2c6dcb12817bf18785a2fdc78e5a1b6669f5
Author: Sebastian <sebasjm@gmail.com>
Date: Fri, 10 Mar 2023 01:21:28 -0300
support http and https
Diffstat:
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/packages/web-util/src/live-reload.ts b/packages/web-util/src/live-reload.ts
@@ -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 {
diff --git a/packages/web-util/src/serve.ts b/packages/web-util/src/serve.ts
@@ -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`);