Help us understand the problem. What is going on with this article?

dynamic rendering で Twitter OGP が表示されないときは Response Header に Content-Type に text/html を入れる

概要

Cloud Front などでホスティングする SPA で OGP イメージを表示するために dynamic rendering をすることがあります。

その際に slack や facebook では表示されるのに、Twitter OGP だけ表示されなかったので、その解決方法を共有します。

解決方法

response header に Content-Type に text/html を入れてレスポンスを返せば表示されます。
Content-Type を指定しないと、ボディの文字列をどのように解釈すればよいかわからないので meta タグを読み込めなかったのだと思います。

aws lambda の例

        const response = {
            body: #html, 
            bodyEncoding: "text",
            headers: {
                "content-type": [
                    {
                        key: "Content-Type",
                        value: "text/html"
                    }
                ]},
            status: 200
        };
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした