在Firebase云功能中部署nestjs

时间:2019-07-17 17:15:28

标签: angular firebase google-cloud-functions nestjs

我想用ssr部署angular应用。最近,我发现有nestjs的原理图可以自动添加ssr功能,但是我没有找到有关如何部署此项目的任何教程或说明,因此可以得到ssr。

我的步骤是:

  1. 使用cli创建一个新的角度应用程序。
  2. 通过“ ng add @ nestjs / ng-universal
  3. 添加nestjs”
  4. 添加云功能并使用Firebase CLI托管
  5. 构建一切
  6. 我将如何部署它,以便该应用程序将位于托管功能上,而nestjs服务器将位于云功能上,并将被调用以进行预渲染。

1 个答案:

答案 0 :(得分:3)

使用Webpack转换firebase deploy文件后,您只需点击index.js。同样,您可以为此建立管道。

处理函数应如下所示:

import * as express from 'express';
import * as functions from 'firebase-functions';
import { AppModule } from './app.module';
import { Express } from 'express';
import { ExpressAdapter } from '@nestjs/platform-express';
import { NestFactory } from '@nestjs/core';

const server: Express = express();

// Create and init Nest server based on Express instance.
const createNestServer = async (expressInstance: Express) => {
  const app = await NestFactory.create(
    AppModule,
    new ExpressAdapter(expressInstance)
  );
  app.listen(4048);
};

createNestServer(server);
exports.angularUniversalFunction = functions.https.onRequest(server); // Export Firebase Cloud Functions to work on

正如您所写,您一切正常,我假设您知道如何为SSR设置所有其他工具。在其他情况下,请查看此演示仓库https://github.com/kamilmysliwiec/universal-nest