Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default gateway bundle #152

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading