在 HTTP 回應後執行

以下範例程式碼會在傳送 HTTP 回應後停止執行。

程式碼範例

Node.js

如要驗證 Cloud Run 函式,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

const functions = require('@google-cloud/functions-framework');

/**
 * HTTP Cloud Function that may not completely
 * execute due to early HTTP response
 *
 * @param {Object} req Cloud Function request context.
 * @param {Object} res Cloud Function response context.
 */
functions.http('afterResponse', (req, res) => {
  res.end();

  // This statement may not execute
  console.log('Function complete!');
});

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 範例瀏覽器