Vue.jsとFirebaseでOGPの表示を行おうとしております。
Vue.js+firebaseでSSRなしにOGP対応する方法
Firebase + SPA で SSR なしに OGP 対応
上記サイトを参考にコードを描いてみたのですがfirebase deploy
をした時に以下のエラーが出ます。
i functions: preparing functions directory for uploading... Error: Error occurred while parsing your function triggers. /Users/a/Desktop/Projects/vue-app/functions/index.js:1 (function (exports, require, module, __filename, __dirname) { import * as functions from 'firebase-functions'; ^ SyntaxError: Unexpected token * at new Script (vm.js:79:7) at createScript (vm.js:251:10) at Object.runInThisContext (vm.js:303:10) at Module._compile (internal/modules/cjs/loader.js:657:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18)
Functionsフォルダ内のindex.jsに記載したコードは以下の通りです。
お力をお貸し頂けると助かります、よろしくお願い致します。
import * as functions from 'firebase-functions'; import * as admin from 'firebase-admin'; admin.initializeApp(functions.config().firebase); const db = admin.firestore() function buildHtmlWithPost(id, obj) { return `<!DOCTYPE html><head> <title>${obj.title}</title> <meta property="og:title" content="${obj.title}"> <meta property="og:image" content="${obj.image}"> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:title" content="${obj.title}"> <meta name="twitter:description" content="${obj.content}"> <meta name="twitter:image" content="${obj.image}"> <link rel="canonical" href="/project/${id}"> </head> <body> <script>window.location="/project?id=${id}";</script> </body> </html>` } exports.project = functions.https.onRequest(function(req, res) { //URLからidを抽出 const path = req.path.split('/') const projectId = path[path.length-1] //idをキーにfirestoreからデータを取得 db.collection('projects').doc(projectId).get() .then((doc) => { let obj = doc.data() //返却用のHTMLを取得 const htmlString = buildHtmlWithPost(projectId, obj) res.set('Cache-Control', 'public, max-age=300, s-maxage=600') res.status(200).end(htmlString) }).catch((err) => { res.status(500).end(err) }) })
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/27 12:52