2017-10-30 4 views
1

클라우드 기능을 사용하여 동적 페이지를 만들려고하지만 로컬에서 cli를 사용하여 제공 할 때 Iam은 공용 폴더에서 index.html 페이지를 가져옵니다.Firebase 호스팅 기능이있는 Firebase 클라우드 기능 : firebase.json "rewrites"

, 내가 중포 기지에서 호스팅 기능을 배포 시도했지만 문제가 여전히 유효은 스피하려고 다음과 같은 코드에 대한

그래서 공용 폴더에서 index.html 페이지를 받고 스피했다 - ​​나는 "문제가 될 생각합니다 부분을 ​​다시 씁니다.

/functions/index.js, 우리가 bigben 기능은 데이터 대응 방법 가야 할 우리가 https://example.firebaseapp.com/을 명중 할 때하려고하고 스피 무엇

{ 
    "hosting": { 
    "public": "public", 

    // Add the following rewrites section *within* "hosting" 
    "rewrites": [ { 
     "source": "/", "function": "bigben" 
    } ] 

    } 
} 

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

exports.bigben = functions.https.onRequest((req, res) => { 
    const hours = (new Date().getHours() % 12) + 1 // london is UTC + 1hr; 
    res.status(200).send(`<!doctype html> 
    <head> 
     <title>Time</title> 
    </head> 
    <body> 
     ${'BONG '.repeat(hours)} 
    </body> 
    </html>`); 
}); 

firebase.json

.

제발 손 좀주세요!

답변

2

Firebase Hosting은 성능상의 이유로 다시 작성하는 것보다 정적 컨텐츠에 대해 항상 일치하는 것을 선호합니다. 공개 디렉토리에서 index.html을 삭제하면 다시 쓰기가 시작됩니다.

+0

감사합니다 @Michael Bleigh, public 디렉토리에서 index.html을 제거한 후 내 기능에서 res를 얻습니다. –