Skip to content

Commit 995e9e5

Browse files
chore: commit pending changes
1 parent 7bb23f9 commit 995e9e5

File tree

14 files changed

+65
-31
lines changed

14 files changed

+65
-31
lines changed

cypress-e2e/config/cypress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export default defineConfig({
120120
localhost8081: 'http://localhost:8081',
121121
localhost8082: 'http://localhost:8082',
122122
localhost8083: 'http://localhost:8083',
123-
localhost8084: 'http://localhost:8084',
123+
localhost8184: 'http://localhost:8184',
124124
localhost9000: 'http://localhost:9000',
125125
localhost9001: 'http://localhost:9001',
126126
localhost9002: 'http://localhost:9002',
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '::1']);
4+
5+
function sanitizeLoopbackHttpUrl(rawUrl) {
6+
const url = new URL(rawUrl);
7+
if (url.protocol !== 'http:') {
8+
throw new Error(`Only http:// loopback URLs are supported for prewarm. Received: ${rawUrl}`);
9+
}
10+
if (!LOOPBACK_HOSTS.has(url.hostname)) {
11+
throw new Error(`Refusing to access non-loopback host "${url.hostname}" for URL: ${rawUrl}`);
12+
}
13+
if (!url.port) {
14+
url.port = '80';
15+
}
16+
return url;
17+
}
18+
19+
module.exports = {
20+
sanitizeLoopbackHttpUrl,
21+
LOOPBACK_HOSTS,
22+
};

federated-css-react-ssr/shell-apps/css-jss/server/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
const express = require('express');
22
const initMiddleware = require('./middleware');
33
const fetch = require('node-fetch');
4+
const { sanitizeLoopbackHttpUrl } = require('../../../server-utils/loopback');
45

56
const app = express();
67
const PORT = 4000;
78

89
async function waitUrl(url, timeout = 300000) {
10+
const target = sanitizeLoopbackHttpUrl(url);
911
const start = Date.now();
1012
// Retry until the remoteEntry.js is available over HTTP
1113
/* eslint-disable no-await-in-loop */
1214
while (true) {
1315
try {
14-
const res = await fetch(url);
16+
const res = await fetch(target.href);
1517
if (res.ok) return;
1618
} catch (_) {}
1719

1820
if (Date.now() - start > timeout) {
1921
// extra diagnostics in CI: try to print which ports are listening
2022
try {
2123
const { execSync } = require('node:child_process');
22-
const ss = execSync(`ss -ltnp | grep :${new URL(url).port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
23-
if (ss) console.log(`[prewarm] port diag ${new URL(url).port}: ${ss}`);
24+
const ss = execSync(`ss -ltnp | grep :${target.port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
25+
if (ss) console.log(`[prewarm] port diag ${target.port}: ${ss}`);
2426
} catch (e) {}
25-
throw new Error(`prewarm timeout for ${url}`);
27+
throw new Error(`prewarm timeout for ${target.href}`);
2628
}
2729
await new Promise(r => setTimeout(r, 5000));
2830
}

federated-css-react-ssr/shell-apps/css-scss/server/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const express = require('express');
22
const initMiddleware = require('./middleware');
33
const fetch = require('node-fetch');
4+
const { sanitizeLoopbackHttpUrl } = require('../../../server-utils/loopback');
45

56
const app = express();
67
const PORT = 4001;
78

89
async function waitUrl(url, timeout = 300000) {
10+
const target = sanitizeLoopbackHttpUrl(url);
911
const start = Date.now();
1012
while (true) {
1113
try {
12-
const res = await fetch(url);
14+
const res = await fetch(target.href);
1315
if (res.ok) return;
1416
} catch (_) {}
1517
if (Date.now() - start > timeout) {
1618
try {
1719
const { execSync } = require('node:child_process');
18-
const ss = execSync(`ss -ltnp | grep :${new URL(url).port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
19-
if (ss) console.log(`[prewarm] port diag ${new URL(url).port}: ${ss}`);
20+
const ss = execSync(`ss -ltnp | grep :${target.port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
21+
if (ss) console.log(`[prewarm] port diag ${target.port}: ${ss}`);
2022
} catch {}
21-
throw new Error(`prewarm timeout for ${url}`);
23+
throw new Error(`prewarm timeout for ${target.href}`);
2224
}
2325
await new Promise(r => setTimeout(r, 5000));
2426
}

federated-css-react-ssr/shell-apps/jss-styled-components-css-module/server/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const express = require('express');
22
const initMiddleware = require('./middleware');
33
const fetch = require('node-fetch');
4+
const { sanitizeLoopbackHttpUrl } = require('../../../server-utils/loopback');
45

56
const app = express();
67
const PORT = 4003;
78

89
async function waitUrl(url, timeout = 300000) {
10+
const target = sanitizeLoopbackHttpUrl(url);
911
const start = Date.now();
1012
while (true) {
1113
try {
12-
const res = await fetch(url);
14+
const res = await fetch(target.href);
1315
if (res.ok) return;
1416
} catch (_) {}
1517
if (Date.now() - start > timeout) {
1618
try {
1719
const { execSync } = require('node:child_process');
18-
const ss = execSync(`ss -ltnp | grep :${new URL(url).port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
19-
if (ss) console.log(`[prewarm] port diag ${new URL(url).port}: ${ss}`);
20+
const ss = execSync(`ss -ltnp | grep :${target.port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
21+
if (ss) console.log(`[prewarm] port diag ${target.port}: ${ss}`);
2022
} catch {}
21-
throw new Error(`prewarm timeout for ${url}`);
23+
throw new Error(`prewarm timeout for ${target.href}`);
2224
}
2325
await new Promise(r => setTimeout(r, 5000));
2426
}

federated-css-react-ssr/shell-apps/jss-styled-components/server/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const express = require('express');
22
const initMiddleware = require('./middleware');
33
const fetch = require('node-fetch');
4+
const { sanitizeLoopbackHttpUrl } = require('../../../server-utils/loopback');
45

56
const app = express();
67
const PORT = 4002;
78

89
async function waitUrl(url, timeout = 300000) {
10+
const target = sanitizeLoopbackHttpUrl(url);
911
const start = Date.now();
1012
while (true) {
1113
try {
12-
const res = await fetch(url);
14+
const res = await fetch(target.href);
1315
if (res.ok) return;
1416
} catch (_) {}
1517
if (Date.now() - start > timeout) {
1618
try {
1719
const { execSync } = require('node:child_process');
18-
const ss = execSync(`ss -ltnp | grep :${new URL(url).port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
19-
if (ss) console.log(`[prewarm] port diag ${new URL(url).port}: ${ss}`);
20+
const ss = execSync(`ss -ltnp | grep :${target.port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
21+
if (ss) console.log(`[prewarm] port diag ${target.port}: ${ss}`);
2022
} catch {}
21-
throw new Error(`prewarm timeout for ${url}`);
23+
throw new Error(`prewarm timeout for ${target.href}`);
2224
}
2325
await new Promise(r => setTimeout(r, 5000));
2426
}

federated-css-react-ssr/shell-apps/less-scss/server/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const express = require('express');
22
const initMiddleware = require('./middleware');
33
const fetch = require('node-fetch');
4+
const { sanitizeLoopbackHttpUrl } = require('../../../server-utils/loopback');
45

56
const app = express();
67
const PORT = 4004;
78

89
async function waitUrl(url, timeout = 300000) {
10+
const target = sanitizeLoopbackHttpUrl(url);
911
const start = Date.now();
1012
while (true) {
1113
try {
12-
const res = await fetch(url);
14+
const res = await fetch(target.href);
1315
if (res.ok) return;
1416
} catch (_) {}
1517
if (Date.now() - start > timeout) {
1618
try {
1719
const { execSync } = require('node:child_process');
18-
const ss = execSync(`ss -ltnp | grep :${new URL(url).port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
19-
if (ss) console.log(`[prewarm] port diag ${new URL(url).port}: ${ss}`);
20+
const ss = execSync(`ss -ltnp | grep :${target.port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
21+
if (ss) console.log(`[prewarm] port diag ${target.port}: ${ss}`);
2022
} catch {}
21-
throw new Error(`prewarm timeout for ${url}`);
23+
throw new Error(`prewarm timeout for ${target.href}`);
2224
}
2325
await new Promise(r => setTimeout(r, 5000));
2426
}

federated-css-react-ssr/shell-apps/scss-tailwind-css/server/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const express = require('express');
22
const initMiddleware = require('./middleware');
33
const fetch = require('node-fetch');
4+
const { sanitizeLoopbackHttpUrl } = require('../../../server-utils/loopback');
45

56
const app = express();
67
const PORT = 4005;
78

89
async function waitUrl(url, timeout = 300000) {
10+
const target = sanitizeLoopbackHttpUrl(url);
911
const start = Date.now();
1012
while (true) {
1113
try {
12-
const res = await fetch(url);
14+
const res = await fetch(target.href);
1315
if (res.ok) return;
1416
} catch (_) {}
1517
if (Date.now() - start > timeout) {
1618
try {
1719
const { execSync } = require('node:child_process');
18-
const ss = execSync(`ss -ltnp | grep :${new URL(url).port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
19-
if (ss) console.log(`[prewarm] port diag ${new URL(url).port}: ${ss}`);
20+
const ss = execSync(`ss -ltnp | grep :${target.port} || true`, { stdio: ['ignore','pipe','ignore'] }).toString().trim();
21+
if (ss) console.log(`[prewarm] port diag ${target.port}: ${ss}`);
2022
} catch {}
21-
throw new Error(`prewarm timeout for ${url}`);
23+
throw new Error(`prewarm timeout for ${target.href}`);
2224
}
2325
await new Promise(r => setTimeout(r, 5000));
2426
}

federated-css/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Note. you don't need to start required remotes separately for this command.
5858

5959
# Running Demo NextJs
6060

61-
Commands will run host NextJs App on `http://localhost:8081-8084/`.
61+
Commands will run host NextJs App on `http://localhost:8081-8184/` (ports 8081, 8082, 8083, 8184).
6262

6363
-`start:nextjs:combination-of-4` -`start:nextjs:jss-tailwind-global` -`start:nextjs:jss-css-and-tailwind-module` -`start:nextjs:less-and-styled-component`
6464

federated-css/consumers-nextjs/less-and-styled-component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"scripts": {
55
"build": "cross-env NEXT_PRIVATE_LOCAL_WEBPACK=true next build",
6-
"start": "cross-env NEXT_PRIVATE_LOCAL_WEBPACK=true next dev -p 8084",
6+
"start": "cross-env NEXT_PRIVATE_LOCAL_WEBPACK=true next dev -p 8184",
77
"lint": "next lint"
88
},
99
"dependencies": {

0 commit comments

Comments
 (0)