Продолжение предыдущего вопроса .
Я подтвердил в консоли firebase, что функции вызываются. Тем не менее, результаты не отображаются в браузере. Я хочу переписать метатег и изменить адрес.
Есть ли проблема с моим кодом?
Браузер не возвращает ошибку.
Разработка выполняется с помощью VueCLI и Firebase.
#create.vue
export default {
components: {},
data() {
return {
//...
};
},
methods: {
async create() {
//After saving data in database, transition page.
this.$router.push({ path: `/s/${this.uuid}` });
}
}
↑ Этот процесс работает.
#router.js
export default new Router({
mode: "history",
base: process.env.BASE_URL,
routes: [
{
path: "/share/:id",
name: "Result",
component: Result
},
Я хочу наконец перевести пользователя в "/ share /: id".
#functions/firebase.json
{
"functions": {
"source": "functions"
},
"hosting": {
"public": "dist",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "/s/*",
"function": "s"
},
{
"source": "**",
"destination": "/index.html"
}
]
}
}
#functions/index.js
const functions = require("firebase-functions");
const express = require("express");
const app = express();
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
const genHtml = (image_url, id) => `
<!DOCTYPE html>
<html>
<head>
//Meta tag to overwrite
</head>
<body>
<script>
location.href = '/share/${id}';
</script>
</body>
</html>
`;
app.get("s/:id", (req, res) => {
const uid = req.params.id;
db.collection("cards")
.doc(uid)
.get()
.then(result => {
if (!result.exists) {
res.status(404).send("404 Not Exist");
} else {
const data = result.data();
const html = genHtml(data.imageurl, uid);
res.set("cache-control", "public, max-age=600, s-maxage=600");
res.send(html);
}
});
});
exports.s = functions.https.onRequest(app);
Я повторил проверку. Убедившись, что этот учебник работает, я также попробовал свои функции.
Затем в браузере отобразится Cannot GET /s/16dc8b71
. Доступный URL-адрес: <domain>/s/<id>
.
Кроме того, на консоли отображается следующая ошибка.
Refused to load the image '<domain>/favicon.ico' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.
Это причина? Я думаю, что это еще одна проблема.