Skip to content

Commit

Permalink
Update default gateway bundle (#152)
Browse files Browse the repository at this point in the history
* fix local dev

* remove pnpm
  • Loading branch information
elliotBraem authored Oct 2, 2024
1 parent 74d34ae commit 4d945f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};

Expand Down
14 changes: 4 additions & 10 deletions lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4d945f1

Please sign in to comment.