首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用firebase函数提供html文件

使用firebase函数提供html文件
EN

Stack Overflow用户
提问于 2018-06-19 08:03:38
回答 1查看 2.2K关注 0票数 0

如何使用firebase函数提供位于我的blog文件夹中的index.html文件。

这是我的文件树

FirebaseWebsite
  │   
  ├── blog
  │   ├── index.html
  │   ├── css
  │   │   ├── fonts
  │   │   │   ├── FontAwesome.otf
  │   │   │   ├── fontawesome-webfont.eot
  │   │   │   ├── fontawesome-webfont.svg
  │   │   │   ├── fontawesome-webfont.ttf
  │   │   │   └── fontawesome-webfont.woff
  │   │   ├── images
  │   │   │   └── banner.jpg
  │   │   └── style.css
  │   ├── fancybox
  │   │   ├── blank.gif
  │   │   ├── fancybox_loading.gif
  │   │   ├── fancybox_loading@2x.gif
  │   │   ├── fancybox_overlay.png
  │   │   ├── fancybox_sprite.png
  │   │   ├── fancybox_sprite@2x.png
  │   │   ├── helpers
  │   │   │   ├── fancybox_buttons.png
  │   │   │   ├── jquery.fancybox-buttons.css
  │   │   │   ├── jquery.fancybox-buttons.js
  │   │   │   ├── jquery.fancybox-media.js
  │   │   │   ├── jquery.fancybox-thumbs.css
  │   │   │   └── jquery.fancybox-thumbs.js
  │   │   ├── jquery.fancybox.css
  │   │   ├── jquery.fancybox.js
  │   │   └── jquery.fancybox.pack.js
  │   ├── js
  │   │   └── script.js
  │   └── tags
  │       └── Topic-for-blog
  │           └── index.html
  ├── index.js
  │
  ├── functions
  │      └── index.js
  │
  ├── Public
  │      └── aboutUs.html
  │
  └── firebase.json

下面是我正在使用的firebase函数

index.js (从functions文件夹)

const functions = require('firebase-functions');
const express   = require('express');
const blogApp   = express();

blogApp.get('/blog', (request, response) => {

    response.sendfile('../blog/public/index.html');
});

exports.blogApp = functions.https.onRequest(blogApp);

下面是配置

firebase.json

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "/blog",
        "function": "blogApp"
      }
    ],
    "cleanUrls": true
  }
}

下面是我访问url时得到的错误

拒绝加载映像'‘,因为它违反了以下内容安全策略指令:"default-src 'self'“。请注意,没有显式设置'img-src‘,因此使用'default-src’作为备用。

任何关于解决这个问题的指导意见都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2018-06-19 08:14:01

在部署函数时,functions文件夹中的所有内容都会打包并发送到Cloud functions。该文件夹之外的任何内容都不会被发送,这意味着您的blog文件夹在运行时不可用(您的静态web内容也不会部署到Firebase托管)。如果您希望部署的代码在运行时可以读取blog的内容,那么在运行deploy命令之前,它应该位于functions文件夹中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50918961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档