Skip to content

Commit 2c84976

Browse files
authored
Merge pull request #2 from jbilinski/jbilinski-patch-1
fix: refine "localhost" matching in printer.service.ts
2 parents e29f973 + 31ed9f4 commit 2c84976

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

apps/server/src/printer/printer.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ export class PrinterService {
101101

102102
let url = publicUrl;
103103

104-
if ([publicUrl, storageUrl].some((url) => url.includes("localhost"))) {
105-
// Switch client URL from `localhost` to `host.docker.internal` in development
104+
if ([publicUrl, storageUrl].some((url) => /https?:\/\/localhost(:\d+)?/.test(url))) {
105+
// Switch client URL from `http[s]://localhost[:port]` to `http[s]://host.docker.internal[:port]` in development
106106
// This is required because the browser is running in a container and the client is running on the host machine.
107-
url = url.replace("localhost", "host.docker.internal");
108-
107+
url = url.replace(/localhost(:\d+)?/, "host.docker.internal");
108+
109109
await page.setRequestInterception(true);
110110

111111
// Intercept requests of `localhost` to `host.docker.internal` in development
112112
page.on("request", (request) => {
113113
if (request.url().startsWith(storageUrl)) {
114-
const modifiedUrl = request.url().replace("localhost", `host.docker.internal`);
114+
const modifiedUrl = request.url().replace(/localhost(:\d+)?/, "host.docker.internal");
115115

116116
void request.continue({ url: modifiedUrl });
117117
} else {

0 commit comments

Comments
 (0)