Skip to content

Commit

Permalink
fix(view): error on domains with multiple subdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceNino committed Jun 9, 2022
1 parent dd8e0a6 commit 756774b
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 6 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 14 additions & 5 deletions apps/view/src/widgets/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
FontAwesomeIconProps,
} from '@fortawesome/react-fontawesome';
import { Button } from 'antd';
import { fromUrl, parseDomain, ParseResultType } from 'parse-domain';
import { toUnicode } from 'punycode';
import { FC, useEffect, useMemo, useState } from 'react';
import styled, { useTheme } from 'styled-components';
import { InfoTable } from '../components/info-table';
Expand Down Expand Up @@ -178,10 +180,17 @@ export const ServerWidget: FC<ServerWidgetProps> = ({ data, config }) => {
return () => clearInterval(interval);
}, [data.uptime]);

const domain = useMemo(
() => window.location.hostname.split('.').slice(-2).join('.'),
[]
);
const domain = useMemo(() => {
const href = window.location.href;
const result = parseDomain(fromUrl(href));

if (result.type === ParseResultType.Listed) {
const { domain, topLevelDomains } = result;
return [toUnicode(domain ?? ''), ...topLevelDomains].join('.');
} else {
return undefined;
}
}, []);

const dateInfos = [
{
Expand Down Expand Up @@ -241,7 +250,7 @@ export const ServerWidget: FC<ServerWidgetProps> = ({ data, config }) => {
/>

<Heading>
{config?.disable_host ? (
{config?.disable_host || !domain ? (
<StandaloneAppendix>dash.</StandaloneAppendix>
) : (
<>
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"cors": "2.8.5",
"express": "4.18.1",
"framer-motion": "6.3.11",
"parse-domain": "7.0.0",
"punycode": "2.1.1",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-is": "18.1.0",
Expand Down
83 changes: 82 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7058,8 +7058,10 @@ __metadata:
inquirer: 8.2.4
jest: 28.1.1
nx: 14.2.2
parse-domain: 7.0.0
prettier: 2.6.2
prop-types: 15.8.1
punycode: 2.1.1
react: 18.1.0
react-dom: 18.1.0
react-is: 18.1.0
Expand Down Expand Up @@ -7094,6 +7096,13 @@ __metadata:
languageName: node
linkType: hard

"data-uri-to-buffer@npm:^4.0.0":
version: 4.0.0
resolution: "data-uri-to-buffer@npm:4.0.0"
checksum: a010653869abe8bb51259432894ac62c52bf79ad761d418d94396f48c346f2ae739c46b254e8bb5987bded8a653d467db1968db3a69bab1d33aa5567baa5cfc7
languageName: node
linkType: hard

"data-urls@npm:^2.0.0":
version: 2.0.0
resolution: "data-urls@npm:2.0.0"
Expand Down Expand Up @@ -8472,6 +8481,16 @@ __metadata:
languageName: node
linkType: hard

"fetch-blob@npm:^3.1.2, fetch-blob@npm:^3.1.4":
version: 3.1.5
resolution: "fetch-blob@npm:3.1.5"
dependencies:
node-domexception: ^1.0.0
web-streams-polyfill: ^3.0.3
checksum: 6493f21bfe196798343431d20c0284835202728d076dd2cbf502a2846679f9265f3b0c3a7224750ae1a770b925da09e592b05fe7c3a22ca27794a39a0039ab21
languageName: node
linkType: hard

"figures@npm:3.2.0, figures@npm:^3.0.0":
version: 3.2.0
resolution: "figures@npm:3.2.0"
Expand Down Expand Up @@ -8717,6 +8736,15 @@ __metadata:
languageName: node
linkType: hard

"formdata-polyfill@npm:^4.0.10":
version: 4.0.10
resolution: "formdata-polyfill@npm:4.0.10"
dependencies:
fetch-blob: ^3.1.2
checksum: 82a34df292afadd82b43d4a740ce387bc08541e0a534358425193017bf9fb3567875dc5f69564984b1da979979b70703aa73dee715a17b6c229752ae736dd9db
languageName: node
linkType: hard

"formstream@npm:^1.1.0":
version: 1.1.1
resolution: "formstream@npm:1.1.1"
Expand Down Expand Up @@ -9854,6 +9882,13 @@ __metadata:
languageName: node
linkType: hard

"ip-regex@npm:^5.0.0":
version: 5.0.0
resolution: "ip-regex@npm:5.0.0"
checksum: 4098b2df89c015f1484a5946e733ec126af8c1828719d90e09f04af23ce487e1a852670e4d3f51b0dc6dfbaf7d8bfab23fd7893ca60e69833da99b7b1ee3623b
languageName: node
linkType: hard

"ip@npm:^1.1.5":
version: 1.1.8
resolution: "ip@npm:1.1.8"
Expand Down Expand Up @@ -10041,6 +10076,15 @@ __metadata:
languageName: node
linkType: hard

"is-ip@npm:^4.0.0":
version: 4.0.0
resolution: "is-ip@npm:4.0.0"
dependencies:
ip-regex: ^5.0.0
checksum: 6bbf3b83b18b02e6cf6b26d16c0d2de38bf5b2f5597de2b902894a83764ae6879f9acd1baec653b47b18a67a975c0cade779f3485e96a6b2cd09a26407d82991
languageName: node
linkType: hard

"is-lambda@npm:^1.0.1":
version: 1.0.1
resolution: "is-lambda@npm:1.0.1"
Expand Down Expand Up @@ -12603,6 +12647,13 @@ __metadata:
languageName: node
linkType: hard

"node-domexception@npm:^1.0.0":
version: 1.0.0
resolution: "node-domexception@npm:1.0.0"
checksum: ee1d37dd2a4eb26a8a92cd6b64dfc29caec72bff5e1ed9aba80c294f57a31ba4895a60fd48347cf17dd6e766da0ae87d75657dfd1f384ebfa60462c2283f5c7f
languageName: node
linkType: hard

"node-emoji@npm:^1.11.0":
version: 1.11.0
resolution: "node-emoji@npm:1.11.0"
Expand All @@ -12626,6 +12677,17 @@ __metadata:
languageName: node
linkType: hard

"node-fetch@npm:^3.2.0":
version: 3.2.6
resolution: "node-fetch@npm:3.2.6"
dependencies:
data-uri-to-buffer: ^4.0.0
fetch-blob: ^3.1.4
formdata-polyfill: ^4.0.10
checksum: ece307ace3a3ff28638ccb0fa0545bb5c0cfd673a9d06fc314d937a73ae6a55917d5bacd7f080f9a9f1449ca20a5c01b1281d0e616acb20315e5ac315971da46
languageName: node
linkType: hard

"node-forge@npm:^1":
version: 1.3.1
resolution: "node-forge@npm:1.3.1"
Expand Down Expand Up @@ -13510,6 +13572,18 @@ __metadata:
languageName: node
linkType: hard

"parse-domain@npm:7.0.0":
version: 7.0.0
resolution: "parse-domain@npm:7.0.0"
dependencies:
is-ip: ^4.0.0
node-fetch: ^3.2.0
bin:
parse-domain-update: bin/update.js
checksum: 41becfda82d3192e70336cb96414403d697e855bfdb463e6ee04ce6bfcd3121534b54229e494e6b1e35e6f93391649d4d1fbf6b1d5c282ec78887ab0f7c6d538
languageName: node
linkType: hard

"parse-json@npm:^4.0.0":
version: 4.0.0
resolution: "parse-json@npm:4.0.0"
Expand Down Expand Up @@ -14408,7 +14482,7 @@ __metadata:
languageName: node
linkType: hard

"punycode@npm:^2.1.0, punycode@npm:^2.1.1":
"punycode@npm:2.1.1, punycode@npm:^2.1.0, punycode@npm:^2.1.1":
version: 2.1.1
resolution: "punycode@npm:2.1.1"
checksum: 823bf443c6dd14f669984dea25757b37993f67e8d94698996064035edd43bed8a5a17a9f12e439c2b35df1078c6bec05a6c86e336209eb1061e8025c481168e8
Expand Down Expand Up @@ -18099,6 +18173,13 @@ __metadata:
languageName: node
linkType: hard

"web-streams-polyfill@npm:^3.0.3":
version: 3.2.1
resolution: "web-streams-polyfill@npm:3.2.1"
checksum: b119c78574b6d65935e35098c2afdcd752b84268e18746606af149e3c424e15621b6f1ff0b42b2676dc012fc4f0d313f964b41a4b5031e525faa03997457da02
languageName: node
linkType: hard

"web-vitals@npm:2.1.4":
version: 2.1.4
resolution: "web-vitals@npm:2.1.4"
Expand Down

0 comments on commit 756774b

Please sign in to comment.