如何使用Firebase函数运行PostgreSQL服务器?



我正在尝试使用Firebase函数运行PostgreSQL服务器。$ npm run build运行,但$ firebase serve --only functions不工作发送错误:

import {
>    ^^^^^^
>     
>    SyntaxError: Cannot use import statement outside a module

实体文件)

我用

  • <
  • 重火力点功能/gh>
  • PostgreSQL

这是我的代码:

  • index.ts

    import * as functions from 'firebase-functions'
    import { router } from './routers'
    import Koa from 'koa'
    import { createConnection } from 'typeorm'
    
    export const app = new Koa()
    const PORT = Number(process.env.PORT) || 8080
    app.proxy = true
    app.use(router.routes()).use(router.allowedMethods())
    const dbServer = async () => {
    try {
    await createConnection()
    app.listen(PORT, () => {
    console.log(`Listening to port ${PORT}`)
    })
    } catch (error) {
    console.log(error)
    }
    }
    dbServer()
    export const api = functions
    .region('asia-northeast3')
    .https.onRequest(app.callback())
    ```
    
  • entity/Channel.ts

    import {
    BaseEntity,
    Entity,
    PrimaryGeneratedColumn
    } from 'typeorm'
    @Entity('Channel')
    export class Channel extends BaseEntity {
    @PrimaryGeneratedColumn()
    id: number
    }
    

如何解决这个问题?

提前感谢!!

Google Cloud Functions是为运行相对较短的进程而设计的。单个Cloud Function可以激活的最长时间是9分钟,之后它的容器将关闭代码。这意味着Cloud Functions不能合理地用于运行您自己的数据库服务器或其他长寿命进程。

考虑使用托管数据库服务,如Cloud SQL。

最新更新