Skip to content

Commit

Permalink
css cors (fixes #50)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xb4lint committed Mar 26, 2024
1 parent f78db49 commit 3c60fa1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"before": false,
"after": true
}],
"@typescript-eslint/no-empty-interface": 0
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/prefer-nullish-coalescing": 0
},
"ignorePatterns": [
"dist/",
Expand Down
2 changes: 1 addition & 1 deletion src/index-html-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class IndexHtmlProcessor {
private removeWebfontTags(html: string): string {
for (const regex of this.webfontRegexes) {
const removeRegex = new RegExp('[ \t]*' + regex.source + '(\r\n|\r|\n)?', 'g');
html = html.replace(removeRegex, '');
html = html.replace(removeRegex, '$1');
}

return html;
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,12 @@ function viteWebfontDownload(
res: ServerResponse,
) => {
void (async () => {
res.setHeader('Content-Type', 'text/css');

try {
await loadAndPrepareDevFonts();

res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Content-Type', 'text/css');

res.end(cssContent);
} catch (error) {
logger.error(
Expand All @@ -336,6 +338,7 @@ function viteWebfontDownload(
const url = req.originalUrl?.replace(/[?#].*$/, '');

res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Content-Type', 'font/' + (url?.replace(/^.*\./, '') || 'woff2'));

res.end(
await downloadFont(
Expand Down

0 comments on commit 3c60fa1

Please sign in to comment.