From 4d945f1c8b065a5d4db5611d7f3a7749ee4c3ba2 Mon Sep 17 00:00:00 2001 From: Elliot Braem <16282460+elliotBraem@users.noreply.github.com> Date: Wed, 2 Oct 2024 08:52:25 -0400 Subject: [PATCH] Update default gateway bundle (#152) * fix local dev * remove pnpm --- lib/dev.ts | 2 +- lib/server.ts | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/dev.ts b/lib/dev.ts index 0d4de13..0852e4c 100644 --- a/lib/dev.ts +++ b/lib/dev.ts @@ -19,7 +19,7 @@ let fileWatcher: null | FSWatcher = null; export const DEFAULT_GATEWAY = { enabled: true, - bundleUrl: "https://ipfs.web4.near.page/ipfs/bafybeibe63hqugbqr4writdxgezgl5swgujay6t5uptw2px7q63r7crk2q/", + bundleUrl: "https://ipfs.web4.near.page/ipfs/bafybeif7ouv5ehif36r6x3eugd3ylh6xyh24a22bbtoxeedwv5d6z45b64/", tagName: "near-social-viewer" }; diff --git a/lib/server.ts b/lib/server.ts index 84da8fe..64d09e9 100644 --- a/lib/server.ts +++ b/lib/server.ts @@ -163,13 +163,9 @@ export function createApp(devJsonPath: string, opts: DevOptions, gateway: Gatewa return async (req: Request, res: Response, _) => { let json = {}; - log.debug(`RPC Request: ${JSON.stringify(req.body)}`); - try { // Make a request to the target rpc json = await fetchJson(proxyUrl, JSON.stringify(req.body)); - - log.debug(`RPC Response: ${json}`); } catch (err) { log.error(err.stack || err.message); return res.status(500).send('Proxy request failed'); @@ -188,7 +184,7 @@ export function createApp(devJsonPath: string, opts: DevOptions, gateway: Gatewa ) { const social_get_key = JSON.parse(atob(params.args_base64)).keys[0]; - log.debug(`Replace with local components for key: ${social_get_key}`); + log.debug(`Redirecting to local component with key: ${social_get_key}`); const devComponents = await readJson(devJsonPath).then( (devJson: DevJson) => { @@ -249,13 +245,11 @@ export function createApp(devJsonPath: string, opts: DevOptions, gateway: Gatewa res.type('text/html').send(modifiedHtml); } else if (path.extname(req.path) === '.js' || path.extname(req.path) === '.css') { // Proxy requests for JS and CSS files - log.debug(`Request for: ${req.path}`); - if (isLocalPath) { - const fullUrl = path.join(__dirname, gateway.bundleUrl, req.path); + const fullUrl = path.join(process.cwd(), gateway.bundleUrl, req.path); try { - log.debug(`Attempting to serve file from local path: ${fullUrl}`); + log.debug(`Serving file from local path: ${fullUrl}`); // Attempt to serve the file from the local path await promises.access(fullUrl); res.sendFile(fullUrl); @@ -347,7 +341,7 @@ async function setupGateway(gateway: GatewayConfig, isLocalPath: boolean, opts: log.debug(`Setting up ${isLocalPath ? "local " : ""}gateway: ${gateway.bundleUrl}`); const manifestUrl = isLocalPath - ? path.join(gateway.bundleUrl, "/asset-manifest.json") + ? path.join(process.cwd(), gateway.bundleUrl, "/asset-manifest.json") : `${gateway.bundleUrl}/asset-manifest.json`; try {