Skip to content

Commit

Permalink
fix Request types of workers, update EvmGateway util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdtanrikulu committed Dec 19, 2023
1 parent 408e569 commit a67001d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
11 changes: 4 additions & 7 deletions arb-gateway/src/tracker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request as CFWRequest } from '@cloudflare/workers-types';
import { Request as ExpressRequest } from 'express';
import { type Request as ExpressRequest } from 'express';

interface TrackerOptions {
apiEndpoint?: string;
Expand Down Expand Up @@ -67,11 +67,8 @@ export class Tracker {

const requestInfo = 'originalUrl' in req ? req : req.headers;

if (
requestInfo.get('Referrer')
) {
body.referrer = requestInfo.get('Referrer') ||
'';
if (requestInfo.get('Referrer')) {
body.referrer = requestInfo.get('Referrer') || '';
}

if (props) {
Expand Down Expand Up @@ -114,4 +111,4 @@ export class Tracker {
console.error('Plausible error:', err);
}
}
}
}
18 changes: 11 additions & 7 deletions arb-gateway/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import { Request as CFWRequest } from '@cloudflare/workers-types';
import { Server } from '@ensdomains/ccip-read-cf-worker';
import type { Router } from '@ensdomains/evm-gateway';
import { InMemoryBlockCache } from './blockCache/InMemoryBlockCache.js';
import { Tracker } from './tracker';
import { Tracker } from './tracker.js';
interface Env {
L1_PROVIDER_URL: string;
L2_PROVIDER_URL: string;
L2_ROLLUP: string;
}

const tracker = new Tracker('arb-gateway-worker.ens-cf.workers.dev', {enableLogging:true});
const logResult = async (request:CFWRequest, result: Response) => {
console.log({request, result})
const tracker = new Tracker('arb-gateway-worker.ens-cf.workers.dev', {
enableLogging: true,
});
const logResult = async (
request: CFWRequest,
result: Response
): Promise<Response> => {
if (!result.body) {
return result;
}
Expand All @@ -28,7 +32,7 @@ const logResult = async (request:CFWRequest, result: Response) => {
};

let app: Router;
async function fetchGateway(request: CFWRequest, env: Env) {
async function fetchGateway(request: CFWRequest, env: Env): Promise<Response> {
// Loading libraries dynamically as a temp work around.
// Otherwise, deployment thorws "Error: Script startup exceeded CPU time limit." error
if (!app) {
Expand Down Expand Up @@ -57,9 +61,9 @@ async function fetchGateway(request: CFWRequest, env: Env) {
gateway.add(server);
app = server.makeApp('/');
}
return app.handle(request).then(logResult.bind(this, request));
return app.handle(request).then(logResult.bind(null, request));
}

export default {
fetch:fetchGateway,
fetch: fetchGateway,
};
Binary file modified bun.lockb
Binary file not shown.
4 changes: 3 additions & 1 deletion evm-gateway/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Request as CFWRequest } from '@cloudflare/workers-types';

export interface Router {
handle: (request: Request) => Promise<boolean>;
handle: (request: CFWRequest) => Promise<Response>;
}
3 changes: 2 additions & 1 deletion l1-gateway/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Request as CFWRequest } from '@cloudflare/workers-types';
import { Server } from '@ensdomains/ccip-read-cf-worker';
import type { Router } from '@ensdomains/evm-gateway';
interface Env {
WORKER_PROVIDER_URL: string;
}
let app: Router;
async function fetch(request: Request, env: Env) {
async function fetch(request: CFWRequest, env: Env) {
// Loading libraries dynamically as a temp work around.
// Otherwise, deployment thorws "Error: Script startup exceeded CPU time limit." error
if (!app) {
Expand Down
3 changes: 2 additions & 1 deletion op-gateway/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Request as CFWRequest } from '@cloudflare/workers-types';
import { Server } from '@ensdomains/ccip-read-cf-worker';
import type { Router } from '@ensdomains/evm-gateway';
interface Env {
Expand All @@ -7,7 +8,7 @@ interface Env {
DELAY: number;
}
let app: Router;
async function fetch(request: Request, env: Env) {
async function fetch(request: CFWRequest, env: Env) {
// Loading libraries dynamically as a temp work around.
// Otherwise, deployment thorws "Error: Script startup exceeded CPU time limit." error
if (!app) {
Expand Down

0 comments on commit a67001d

Please sign in to comment.