{"id":16924,"date":"2023-09-21T11:28:57","date_gmt":"2023-09-21T02:28:57","guid":{"rendered":"https:\/\/sendgrid.kke.co.jp\/blog\/?p=16924"},"modified":"2023-09-21T11:28:57","modified_gmt":"2023-09-21T02:28:57","slug":"supabase%e3%81%aeedge-functions%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6twilio-sendgrid%e3%81%ae%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%92%e9%80%81%e4%bf%a1%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/sendgrid.kke.co.jp\/blog\/?p=16924","title":{"rendered":"Supabase\u306eEdge Functions\u3092\u4f7f\u3063\u3066Twilio SendGrid\u306e\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/20230921_blog.png\" alt=\"Supabase\u306eEdge Functions\u3092\u4f7f\u3063\u3066Twilio SendGrid\u306e\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5\" width=\"100%\" class=\"aligncenter size-full wp-image-16925\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/20230921_blog.png 650w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/20230921_blog-300x185.png 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>Twilio SendGrid\u30b5\u30dd\u30fc\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u83ca\u7530(<a href=\"https:\/\/twitter.com\/kikutaro_\" rel=\"noopener\" target=\"_blank\">@kikutaro_<\/a>)\u3067\u3059\u3002<a href=\"https:\/\/supabase.com\/\" rel=\"noopener\" target=\"_blank\">Supabase<\/a>\u306f\u3001Firebase\u306e\u4ee3\u66ff\u3068\u547c\u3070\u308c\u308b\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u306e\u30d7\u30ed\u30c0\u30af\u30c8\u3067\u3059\u3002DB\u3084\u8a8d\u8a3c\u306a\u3069\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306e\u958b\u767a\u306b\u5fc5\u8981\u306a\u6a5f\u80fd\u304c\u4e00\u5f0f\u63c3\u3063\u3066\u3044\u307e\u3059\u3002\u4eca\u56de\u306e\u30d6\u30ed\u30b0\u3067\u306f\u3001Supabase\u304c\u6301\u3064\u6a5f\u80fd\u306e1\u3064\u300c<a href=\"https:\/\/supabase.com\/docs\/guides\/functions\/quickstart\" rel=\"noopener\" target=\"_blank\">Edge Functions<\/a>\u300d\u3092\u4f7f\u3063\u3066\u3001SendGrid\u306e\u30e1\u30fc\u30eb\u3092\u9001\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/1.png\" alt=\"Supabase\" width=\"100%\" class=\"aligncenter size-full wp-image-16926\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/1.png 1430w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/1-300x151.png 300w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/1-768x388.png 768w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/1-1024x517.png 1024w\" sizes=\"(max-width: 1430px) 100vw, 1430px\" \/><\/p>\n<p>\u4eca\u56de\u8a66\u3057\u305f\u74b0\u5883\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li>Windows 11 Pro<\/li>\n<li>Rancher Desktop\u4e0a\u306eDebian 11\uff08bullseye\uff09<\/li>\n<li>npm 9.6.7<\/li>\n<\/ul>\n<h3>Supabase\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u4f5c\u6210<\/h3>\n<p><a href=\"https:\/\/supabase.com\/\" rel=\"noopener\" target=\"_blank\">Supabase<\/a>\u306bSign Up\u3057\u3066\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u53d6\u5f97\u3057\u305f\u3089\u3001\u306f\u3058\u3081\u306b\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/image4.png\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/image4.png\" alt=\"\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\" width=\"100%\" class=\"aligncenter size-full wp-image-16932\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/image4.png 977w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/image4-300x183.png 300w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/image4-768x469.png 768w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/a><\/p>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u3001Region\u3092\u6307\u5b9a\u3057\u3066\u300cCreate new project\u300d\u3092\u62bc\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/3.png\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/3.png\" alt=\"\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u3001Region\u3092\u6307\u5b9a\" width=\"100%\" class=\"aligncenter size-full wp-image-16928\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/3.png 692w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/3-283x300.png 283w\" sizes=\"(max-width: 692px) 100vw, 692px\" \/><\/a><\/p>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210\u5f8c\u306b\u8868\u793a\u3055\u308c\u308bURL\u306b\u306f\u53c2\u7167\u7528\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8ID\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\nhttps:\/\/supabase.com\/dashboard\/project\/abcdefghijklmnopqrstu\/building<\/p>\n<p>\u3053\u306e\u5834\u5408\u306f\u300cabcdefghijklmnopqrstu\u300d\u3067\u3059\u3002\u5f8c\u307b\u3069\u4f7f\u3046\u306e\u3067\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>Supabase CLI\u306e\u6e96\u5099<\/h3>\n<p>\u30bf\u30fc\u30df\u30ca\u30eb\u3092\u958b\u3044\u3066\u3001npm\u3067<a href=\"https:\/\/github.com\/supabase\/cli\" rel=\"noopener\" target=\"_blank\">CLI<\/a>\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nnpm i supabase --save-dev\r\n<\/pre>\n<p>supabase\u30b3\u30de\u30f3\u30c9\u306f\u982d\u306bnpx\u3092\u4ed8\u3051\u3066\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nnpx supabase -v\r\n1.93.0\r\n<\/pre>\n<h3>Edge Function\u306e\u4f5c\u6210<\/h3>\n<p>\u7d9a\u3044\u3066Edge Function\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002sendgrid\u3068\u3044\u3046\u540d\u79f0\u306efunction\u3092\u65b0\u305f\u306b\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nnpx supabase functions new sendgrid\r\n<\/pre>\n<p>\u4f5c\u6210\u3055\u308c\u305findex.ts\u3092\u6b21\u306e\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u307e\u3059\u3002\u5b9b\u5148\u306eto@example.com\u3068\u9001\u4fe1\u5143\u306efrom@example.com\u306f\u3001\u5b9f\u969b\u306b\u3054\u81ea\u8eab\u304c\u304a\u6301\u3061\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"brush: jscript; highlight: [15,18]; title: ; notranslate\" title=\"\">\r\nimport { serve } from &quot;https:\/\/deno.land\/std@0.196.0\/http\/server.ts&quot;;\r\n\r\nconst SG_API_KEY = Deno.env.get('SG_API_KEY')\r\n\r\nconst handler = async (_request: Request): Promise&lt;Response&gt; =&gt; {\r\n  const res = await fetch(&quot;https:\/\/api.sendgrid.com\/v3\/mail\/send&quot;, {\r\n    method: 'POST',\r\n    headers: {\r\n      'Content-Type': 'application\/json',\r\n      'Authorization': 'Bearer ' + SG_API_KEY,\r\n    },\r\n    body: JSON.stringify({\r\n      &quot;personalizations&quot;: &#x5B;\r\n        {\r\n          &quot;to&quot;: &#x5B;{&quot;email&quot;: &quot;to@example.com&quot;}]\r\n        }\r\n      ],\r\n      &quot;from&quot;: {&quot;email&quot;: &quot;from@example.com&quot;},\r\n      &quot;subject&quot;: &quot;\u30c6\u30b9\u30c8&quot;,\r\n      &quot;content&quot;: &#x5B;\r\n        {\r\n          &quot;type&quot;: &quot;text\/plain&quot;,\r\n          &quot;value&quot;: &quot;\u30c6\u30b9\u30c8&quot;\r\n        },\r\n        {\r\n          &quot;type&quot;: &quot;text\/html&quot;,\r\n          &quot;value&quot;: &quot;&lt;html&gt;&lt;head&gt;&lt;\/head&gt;&lt;body&gt;\u30c6\u30b9\u30c8&lt;\/body&gt;&lt;\/html&gt;&quot;\r\n        }\r\n      ]\r\n    }),\r\n  });\r\n\r\n  return new Response(res.body, {\r\n    status: res.status,\r\n    headers: {\r\n      'Content-Type': 'application\/json',\r\n    },\r\n  });\r\n};\r\n\r\nserve(handler);\r\n<\/pre>\n<p>\u6b21\u306b\u74b0\u5883\u5909\u6570\u306e\u30d5\u30a1\u30a4\u30eb\uff08.env\uff09\u3092\u7528\u610f\u3057\u3066\u3001SendGrid\u306eAPI\u30ad\u30fc\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002API\u30ad\u30fc\u306e\u4f5c\u6210\u65b9\u6cd5\u306f<a href=\"https:\/\/sendgrid.kke.co.jp\/docs\/User_Manual_JP\/Settings\/api_keys.html#-Create-an-API-Key\" rel=\"noopener\" target=\"_blank\">\u3053\u3061\u3089<\/a>\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSG_API_KEY=SG.xxxxxxxxxxxxxxxxxxxxxxxx\r\n<\/pre>\n<h3>\u30c7\u30d7\u30ed\u30a4<\/h3>\n<p>\u3053\u308c\u3067\u6e96\u5099\u306f\u6574\u3063\u305f\u306e\u3067\u3001\u3042\u3068\u306f\u74b0\u5883\u5909\u6570\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u30bb\u30c3\u30c8\u3057\u3066function\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u3060\u3051\u3067\u3059\u3002\u4eca\u56de\u306f\u52d5\u4f5c\u78ba\u8a8d\u3092\u7c21\u5358\u306b\u884c\u3046\u305f\u3081\u3001JWT\u306b\u3088\u308b\u8a8d\u8a3c\u3092\u5916\u3059\u300c&#45;&#45;no&#45;verify&#45;jwt\u300d\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u3066\u30c7\u30d7\u30ed\u30a4\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nnpx supabase secrets set --env-file .env --project-ref abcdefghijklmnopqrstu\r\nnpx supabase functions deploy sendgrid --project-ref abcdefghijklmnopqrstu --no-verify-jwt \r\n<\/pre>\n<p>\u6b21\u306e\u3088\u3046\u306a\u8868\u793a\u304c\u51fa\u308c\u3070\u30c7\u30d7\u30ed\u30a4\u6210\u529f\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nVersion 1.30.3 is already installed\r\nBundling sendgrid\r\nDeploying sendgrid (script size: 22.79kB)\r\nDeployed Function sendgrid on project abcdefghijklmnopqrstu\r\nYou can inspect your deployment in the Dashboard: https:\/\/supabase.com\/dashboard\/project\/abcdefghijklmnopqrstu\/functions\/sendgrid\/details\r\n<\/pre>\n<p>\u305d\u308c\u3067\u306f\u3001\u30c7\u30d7\u30ed\u30a4\u3055\u308c\u305fFunction\u3092\u547c\u3073\u51fa\u3057\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3092\u884c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002curl\u30b3\u30de\u30f3\u30c9\u3067sendgrid function\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncurl -I -X POST 'https:\/\/sdfdiepotzslqwgpxqtd.supabase.co\/functions\/v1\/sendgrid'\r\n<\/pre>\n<p>202\u306e\u5fdc\u7b54\uff08\u30ea\u30af\u30a8\u30b9\u30c8\u53d7\u4ed8\uff09\u304c\u8fd4\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nHTTP\/2 202 \r\ndate: Wed, 13 Sep 2023 05:46:24 GMT\r\ncontent-type: application\/json\r\ncf-ray: 805e16e488c6afbe-NRT\r\ncf-cache-status: DYNAMIC\r\nstrict-transport-security: max-age=2592000; includeSubDomains\r\nvary: Accept-Encoding\r\nx-sb-edge-region: ap-northeast-1\r\nx-served-by: supabase-edge-runtime\r\nserver: cloudflare\r\nalt-svc: h3=&quot;:443&quot;; ma=86400\r\n<\/pre>\n<p>\u5b9f\u969b\u306b\u5b9b\u5148\u3092\u307f\u3066\u307f\u308b\u3068\u2026\u30e1\u30fc\u30eb\u304c\u5c4a\u3044\u3066\u3044\u307e\u3059\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/4.png\" alt=\"\u5c4a\u3044\u305f\u30e1\u30fc\u30eb\" width=\"100%\" class=\"aligncenter size-full wp-image-16929\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/4.png 837w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/4-300x142.png 300w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2023\/09\/4-768x363.png 768w\" sizes=\"(max-width: 837px) 100vw, 837px\" \/><\/p>\n<h3>\u304a\u308f\u308a\u306b<\/h3>\n<p>\u4eca\u56de\u306fSupabase\u306eEdge Functions\u3092\u5229\u7528\u3057\u3066SendGrid\u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u3092\u884c\u3044\u307e\u3057\u305f\u3002\u6700\u8fd1\u3001Function\u6a5f\u80fd\u3092\u63d0\u4f9b\u3059\u308bBaaS\u304c\u5897\u3048\u3066\u3044\u307e\u3059\u306d\u3002\u4eca\u5f8c\u3001\u4ed6\u306e\u30b5\u30fc\u30d3\u30b9\u3067\u3082\u8a66\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Twilio SendGrid\u30b5\u30dd\u30fc\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u83ca\u7530(@kikutaro_)\u3067\u3059\u3002Supabase\u306f\u3001Firebase\u306e\u4ee3\u66ff\u3068\u547c\u3070\u308c\u308b\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u306e\u30d7\u30ed\u30c0\u30af\u30c8\u3067\u3059\u3002DB\u3084\u8a8d\u8a3c\u306a\u3069\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306e\u958b\u767a\u306b\u5fc5\u8981\u306a\u6a5f\u80fd\u304c\u4e00\u5f0f\u63c3 <a class=\"read-more\" href=\"https:\/\/sendgrid.kke.co.jp\/blog\/?p=16924\">&#8230;\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":9,"featured_media":16925,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-16924","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technical"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16924","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16924"}],"version-history":[{"count":9,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16924\/revisions"}],"predecessor-version":[{"id":16942,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16924\/revisions\/16942"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/media\/16925"}],"wp:attachment":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}