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

[Bug]: 416 error when generating LinkedIn post preview for static app #377

Closed
vamsivishnu opened this issue May 2, 2023 · 5 comments
Closed

Comments

@vamsivishnu
Copy link

Problem description

We have a web app hosted on Deno Deploy that has a small API but serves static content to the browser via the std/http/file_server.ts library. The app is accessible via https://stillme.app and we are trying to ensure that open graph post previews work, and they do in all places except LinkedIn.

We used their Post Inspector tool and saw that their crawler receives a 416 error when trying to access our app. Almost no other details are provided. (Sometimes it fails with a server error instead, but we see the 416 more often.)

Our experience is identical to an Azure Static Web App issue reported here, which seemed to be resolved by the Azure team on their side: Azure/static-web-apps#57

We are trying to reproduce using a sharable example, but figured we'd post the question while we do that. We are unable to reproduce with any apps that do not use the file_server, e.g. merch.deno.com, the Fresh demo app, etc.

Steps to reproduce

  1. Open the Post Inspector tool.
  2. Try to generate a preview for https://stillme.app

Expected behavior

We expect a preview to be generated with a 200 OK status.

Environment

Code snippet of the main.ts entrypoint:

import { serve } from "https://deno.land/std@0.185.0/http/server.ts";
import { serveDir } from "https://deno.land/std@0.185.0/http/file_server.ts";

async function handler(req: Request): Promise<Response> {
  // Check if the route is "api" and handle
  ...

  // Serve the static web app if no route matches.
  return serveDir(req, {
    fsRoot: "app",
  });
}

serve(handler, { port: 8080 });

Possible solution

No response

Additional context

No response

@ayame113
Copy link

ayame113 commented May 2, 2023

linkedin Post Inspector sends range: bytes=0-3145727 headers. Currently, std's file server considers 3145727 to be a bad range request and rejects it with status 416.

Other servers seem to respond with a 206 Partial Content if they receive such a request. I think we need to change your std's fileserver implementation to not give an error here. (II am fixing in denoland/std#3353)

@vamsivishnu
Copy link
Author

@ayame113 Thank you so much for digging into this! Out of curiosity, how did you determine the headers sent by the Post Inspector?

@ayame113
Copy link

ayame113 commented May 3, 2023

I deployed a server like below in deno deploy and generated a preview in Post Inspector. After that I saw the header in the log.

import { serve } from "https://deno.land/std@0.185.0/http/server.ts";

serve((req: Request) => {
  console.log([...req.headers]);
  new Response("Hello World");
});

@ayame113
Copy link

ayame113 commented May 4, 2023

A new version of std has been published (https://github.com/denoland/deno_std/releases/tag/0.186.0). Hopefully the problem should have been fixed.

@vamsivishnu
Copy link
Author

After upgrading our dependencies to 0.186.0, the problem is resolved! Thank you so much for your help in identifying the issue and supplying the fix!

Post Inspector for confirmation of fix: https://www.linkedin.com/post-inspector/inspect/stillme.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants