Облачная функция Google не запускается - PullRequest
0 голосов
/ 30 апреля 2020

Я пытаюсь запустить облачную функцию Google при достижении пути моего хостинга.

Итак, я добавил это на свою базу данных. json

"rewrites": [
  {
    "source": "**",
    "destination": "/index.html",
    "function": "app"
  } 

здесь моя функция называется "app" :

[...]
server.get('*', (req:any,res:any) => {
 const isBot = detectBot(req.headers['user-agent']);

 if(isBot) {
     const botUrl = generateUrl(req);

     nf(`${renderUrl}/${botUrl}`)
     .then((r: { text: () => any; }) => r.text())
     .then((body: { toString: () => any; }) => {
         res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
         res.set('Vary','User-Agent');
         res.send(body.toString())
     });
 } else {
    nf(`https://${appUrl}`)
    .then((r: { text: () => any; }) => r.text())
    .then((body: { toString: () => any; }) => {
        res.send(body.toString());
    });
 }


});


exports.app = functions.https.onRequest(server);

Функция "app" и веб-сайт развернуты, но при достижении URL-адреса функция "app" не срабатывает.

Заранее спасибо.

1 Ответ

0 голосов
/ 30 апреля 2020

Ваш раздел "перезаписывает" неправильно настроен. Вы указываете и пункт назначения ("/index.html") и параметр функции. Вот пример переписывания, который будет направлять запросы на /function-url вашей функции app и другие запросы (неопределенные или "/ foo" и "/ foo / **") на ваши index.html:

"rewrites": [ {
    // Serves index.html for requests to files or directories that do not exist
    "source": "**",
    "destination": "/index.html"
  }, {
    // Serves index.html for requests to both "/foo" and "/foo/**"
    // Using "/foo/**" only matches paths like "/foo/xyz", but not "/foo"
    "source": "/foo{,/**}",
    "destination": "/index.html"
  }, {
    // calls your app function for requests to "/function-url"
    "source": "/function-url",
    "function": "app"
  } ]

Подробнее о том, как настроить перезапись здесь .

...