谷歌函数v2和NestJs



我正在研究使用谷歌云函数v2构建一个带有nest的api,看起来有些人正在使用nx:https://itnext.io/a-perfect-match-nestjs-cloud-functions-2nd-gen-nx-workspace-f13fb044e9a4,这可以使用nx完成吗?

我正在研究一个更普通的例子,只使用函数框架和嵌套。有人能给我举个例子吗?

谢谢!

Nx只是一个工具。它应该与您在没有NX的情况下实现的相同。你能在普通的Nestjs项目中尝试一下吗?
// main.ts
const server = express()
import { http } from '@google-cloud/functions-framework'
export const createNestServer = async (expressInstance) => {
const app = await NestFactory.create(AppModule, new ExpressAdapter(expressInstance))
const globalPrefix = 'api'
app.setGlobalPrefix(globalPrefix)
app.enableCors()
return app.init()
}
createNestServer(server)
.then((v) => {
if (environment.production) {
Logger.log('🚀 Starting production server...')
} else {
Logger.log(`🚀 Starting development server on http://localhost:${process.env.PORT || 3333}`)
v.listen(process.env.PORT || 3333)
}
})
.catch((err) => Logger.error('Nest broken', err))
http('apiNEST', server)

最新更新