aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-03-10 01:21:28 -0300
committerSebastian <sebasjm@gmail.com>2023-03-10 01:21:28 -0300
commit0fb6c098d78de77d100ef405585040118aa61312 (patch)
tree95eacffb5f9dbbe307c30566785ac939f47fabed
parent034f2c6dcb12817bf18785a2fdc78e5a1b6669f5 (diff)
support http and https
-rw-r--r--packages/web-util/src/live-reload.ts3
-rw-r--r--packages/web-util/src/serve.ts6
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
index 74d542956..48093088a 100644
--- 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
index 34982c656..597303ba2 100644
--- 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`);