Explorar o código

fix: add cors headers to http server

Sv443 hai 3 meses
pai
achega
eac5af458e
Modificáronse 3 ficheiros con 34 adicións e 0 borrados
  1. 2 0
      package.json
  2. 28 0
      pnpm-lock.yaml
  3. 4 0
      src/tools/serve.ts

+ 2 - 0
package.json

@@ -83,6 +83,7 @@
     "@storybook/html": "^8.1.10",
     "@storybook/html-vite": "^8.1.10",
     "@storybook/test": "^8.1.10",
+    "@types/cors": "^2.8.17",
     "@types/dompurify": "^3.0.5",
     "@types/express": "^4.17.21",
     "@types/greasemonkey": "^4.0.7",
@@ -91,6 +92,7 @@
     "@typescript-eslint/parser": "^8.0.0",
     "@typescript-eslint/utils": "^8.0.0",
     "concurrently": "^9.0.1",
+    "cors": "^2.8.5",
     "dotenv": "^16.4.5",
     "eslint": "^9.5.0",
     "eslint-plugin-storybook": "^0.11.0",

+ 28 - 0
pnpm-lock.yaml

@@ -63,6 +63,9 @@ importers:
       '@storybook/test':
         specifier: ^8.1.10
         version: 8.1.10
+      '@types/cors':
+        specifier: ^2.8.17
+        version: 2.8.17
       '@types/dompurify':
         specifier: ^3.0.5
         version: 3.0.5
@@ -87,6 +90,9 @@ importers:
       concurrently:
         specifier: ^9.0.1
         version: 9.0.1
+      cors:
+        specifier: ^2.8.5
+        version: 2.8.5
       dotenv:
         specifier: ^16.4.5
         version: 16.4.5
@@ -1880,6 +1886,9 @@ packages:
   '@types/[email protected]':
     resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==}
 
+  '@types/[email protected]':
+    resolution: {integrity: sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==}
+
   '@types/[email protected]':
     resolution: {integrity: sha512-fXRhhUkG4H3TQk5dBhQ7m/JDdSNHKwR2BBia62lhwEIq9xGiQKLxd6LymNhn47SjXhsUEPmxi+PKw2OkW4LLjA==}
 
@@ -2465,6 +2474,10 @@ packages:
   [email protected]:
     resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
 
+  [email protected]:
+    resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==}
+    engines: {node: '>= 0.10'}
+
   [email protected]:
     resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
 
@@ -3640,6 +3653,10 @@ packages:
     engines: {node: ^14.16.0 || >=16.10.0}
     hasBin: true
 
+  [email protected]:
+    resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}
+    engines: {node: '>=0.10.0'}
+
   [email protected]:
     resolution: {integrity: sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==}
     engines: {node: '>= 0.4'}
@@ -6850,6 +6867,10 @@ snapshots:
     dependencies:
       '@types/node': 20.14.8
 
+  '@types/[email protected]':
+    dependencies:
+      '@types/node': 20.14.8
+
   '@types/[email protected]':
     dependencies:
       '@types/node': 20.14.8
@@ -7491,6 +7512,11 @@ snapshots:
 
   [email protected]: {}
 
+  [email protected]:
+    dependencies:
+      object-assign: 4.1.1
+      vary: 1.1.2
+
   [email protected]: {}
 
   [email protected]:
@@ -8736,6 +8762,8 @@ snapshots:
       pathe: 1.1.2
       ufo: 1.5.3
 
+  [email protected]: {}
+
   [email protected]: {}
 
   [email protected]:

+ 4 - 0
src/tools/serve.ts

@@ -2,6 +2,7 @@ import { resolve } from "node:path";
 import { fileURLToPath } from "node:url";
 import type { Server } from "node:http";
 import express, { NextFunction, Request, Response } from "express";
+import cors from "cors";
 import k from "kleur";
 import "dotenv/config";
 import { outputDir } from "../../rollup.config.mjs";
@@ -20,6 +21,9 @@ const autoExitRaw = argv.find(arg => arg.startsWith("--auto-exit-time="))?.split
 const autoExitTime: number | undefined = !isNaN(Number(autoExitRaw)) ? Number(autoExitRaw) * 1000 : undefined;
 
 const app = express();
+
+app.use(cors());
+
 let server: Server;
 
 enableLogging && app.use((_req, _res, next) => {