From a7dda85451efb926664787006f8b6f2ff2497657 Mon Sep 17 00:00:00 2001 From: eerkaijun Date: Fri, 19 Jan 2024 18:43:43 -0500 Subject: [PATCH] manage cors --- paymaster/package.json | 2 ++ paymaster/pnpm-lock.yaml | 33 +++++++++++++++++++++++++++++---- paymaster/src/server.ts | 4 ++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/paymaster/package.json b/paymaster/package.json index 36c8aa8..be7b30e 100644 --- a/paymaster/package.json +++ b/paymaster/package.json @@ -16,8 +16,10 @@ "@types/body-parser": "^1.19.2", "@types/express": "^4.17.17", "@types/node": "^20.5.7", + "@types/cors": "^2.8.17", "axios": "^1.5.0", "body-parser": "^1.20.2", + "cors": "^2.8.5", "dotenv": "^16.3.1", "ethers": "^6.7.1", "express": "^4.18.2", diff --git a/paymaster/pnpm-lock.yaml b/paymaster/pnpm-lock.yaml index 1756074..eafc435 100644 --- a/paymaster/pnpm-lock.yaml +++ b/paymaster/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + dependencies: '@ethersproject/bytes': specifier: ^5.7.0 @@ -7,6 +11,9 @@ dependencies: '@types/body-parser': specifier: ^1.19.2 version: 1.19.2 + '@types/cors': + specifier: ^2.8.17 + version: 2.8.17 '@types/express': specifier: ^4.17.17 version: 4.17.17 @@ -19,6 +26,9 @@ dependencies: body-parser: specifier: ^1.20.2 version: 1.20.2 + cors: + specifier: ^2.8.5 + version: 2.8.5 dotenv: specifier: ^16.3.1 version: 16.3.1 @@ -69,6 +79,12 @@ packages: '@types/node': 20.5.7 dev: false + /@types/cors@2.8.17: + resolution: {integrity: sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==} + dependencies: + '@types/node': 20.5.7 + dev: false + /@types/express-serve-static-core@4.17.36: resolution: {integrity: sha512-zbivROJ0ZqLAtMzgzIUC4oNqDG9iF0lSsAqpOD9kbs5xcIM3dTiyuHvBc7R8MtWBp3AAWGaovJa+wzWPjLYW7Q==} dependencies: @@ -240,6 +256,14 @@ packages: engines: {node: '>= 0.6'} dev: false + /cors@2.8.5: + resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==} + engines: {node: '>= 0.10'} + dependencies: + object-assign: 4.1.1 + vary: 1.1.2 + dev: false + /debug@2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} peerDependencies: @@ -490,6 +514,11 @@ packages: engines: {node: '>= 0.6'} dev: false + /object-assign@4.1.1: + resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} + engines: {node: '>=0.10.0'} + dev: false + /object-inspect@1.12.3: resolution: {integrity: sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==} dev: false @@ -662,7 +691,3 @@ packages: utf-8-validate: optional: true dev: false - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false diff --git a/paymaster/src/server.ts b/paymaster/src/server.ts index 32ac0fb..835f555 100644 --- a/paymaster/src/server.ts +++ b/paymaster/src/server.ts @@ -1,5 +1,6 @@ import express, { Express, Request, Response } from 'express'; import bodyParser from 'body-parser'; +import cors from 'cors'; import { sponsorTransaction, UserOperation } from './rpcMethods'; type JsonRpcRequestBody = { @@ -13,6 +14,9 @@ const port = 3000; app.use(bodyParser.json()); +// Use cors middleware to enable CORS +app.use(cors({ origin: '*' })); + app.post('/', async(req: Request, res: Response) => { const { id, method, params } = req.body as JsonRpcRequestBody;