Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Fix font (#597)

Sean Boulta7553b3ade5f
diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs
index 3f616e0f..652908f5 100644
--- a/apps/web/next.config.mjs
+++ b/apps/web/next.config.mjs
@@ -10,8 +10,23 @@ const millionConfig = {
auto: { rsc: true },
};
+const isProd = process.env.NODE_ENV === 'production';
/** @type {import("next").NextConfig} */
const nextConfig = {
+ async headers() {
+ return !isProd
+ ? [
+ {
+ // allow CORS only on dev for admin site to get monaco files
+ source: 'min/vs/(.*)',
+ headers: [
+ { key: 'Access-Control-Allow-Origin', value: '*' },
+ { key: 'Access-Control-Allow-Methods', value: 'GET' },
+ ],
+ },
+ ]
+ : [];
+ },
webpack: (config) => {
config.module.rules.push({
test: /\.md$/,
diff --git a/apps/web/public/min/vs/base/browser/ui/codicons/codicon/codicon.ttf b/apps/web/public/min/vs/base/browser/ui/codicons/codicon/codicon.ttf
index a45dd3aa..91105610 100644
Binary files a/apps/web/public/min/vs/base/browser/ui/codicons/codicon/codicon.ttf and b/apps/web/public/min/vs/base/browser/ui/codicons/codicon/codicon.ttf differ
diff --git a/packages/monaco/src/code-editor.tsx b/packages/monaco/src/code-editor.tsx
index d6142f1b..f39acf7a 100644
--- a/packages/monaco/src/code-editor.tsx
+++ b/packages/monaco/src/code-editor.tsx
@@ -6,19 +6,24 @@ import { useMemo } from 'react';
import { useEditorSettingsStore } from './settings-store';
import { libSource } from './editor-types';
-const PROD_URL = 'https://typehero.dev';
-const STAGING_URL = 'https://staging.typehero.dev';
-const MONACO_URL = `${
- process.env.NODE_ENV !== 'production'
- ? 'http://localhost:3000'
- : process.env.STAGING
- ? STAGING_URL
- : PROD_URL
-}/min/vs`;
+const ADMIN_HOST = 'admin.typehero.dev';
+const getBaseUrl = () => {
+ if (typeof globalThis.window === 'undefined') return '';
+ const isProd = process.env.NODE_ENV === 'production';
+ if (isProd && window?.location?.hostname === ADMIN_HOST) {
+ return 'https://typehero.dev';
+ }
+
+ if (!isProd && window?.location?.port === '3001') {
+ return 'http://localhost:3000';
+ }
+
+ return '';
+};
loader.config({
paths: {
- vs: MONACO_URL,
+ vs: `${getBaseUrl()}/min/vs`,
},
});
diff --git a/tooling/scripts/dl-monaco.ts b/tooling/scripts/dl-monaco.ts
index 393d7504..dc9df1b2 100644
--- a/tooling/scripts/dl-monaco.ts
+++ b/tooling/scripts/dl-monaco.ts
@@ -34,19 +34,33 @@ async function downloadAndSaveFile([remoteUrl, diskPath = remoteUrl, appendToSta
diskPath?: string,
appendToStart?: (dl: string) => string,
]) {
- const textToWrite = await (
+ // if it's a ttf use blob
+ const isBinary = remoteUrl.endsWith('.ttf');
+
+ const fileArrayData = await (
await fetchFile({
url: new URL(TS_CDN_BASE_URL + remoteUrl),
retries: 5,
})
- ).text();
+ )[isBinary ? 'blob' : 'text']();
const pathToSave = url.fileURLToPath(
path.join(import.meta.url, '../../../apps/web/public', diskPath),
);
const dir = path.join(pathToSave, '../');
await fs.mkdir(dir, { recursive: true });
- await fs.writeFile(pathToSave, appendToStart?.(textToWrite) ?? textToWrite, {});
+
+ // TODO: fix this if someone fucks up the options
+ if (isBinary) {
+ const data = Buffer.from(await (fileArrayData as Blob).arrayBuffer());
+ await fs.writeFile(pathToSave, data);
+ } else {
+ await fs.writeFile(
+ pathToSave,
+ appendToStart?.(fileArrayData as string) ?? (fileArrayData as string),
+ {},
+ );
+ }
}
const files = [