Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@ikamirin

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

More than 1 year has passed since last update.

概要

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
        };
0
Help us understand the problem. What is going on with this article?
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
ikamirin

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?