liwenka1
V2EX  ›  Node.js

有大佬讲一下 nest 部署到 vercel 的流程吗?

  •  
  •   liwenka1 · Jun 4, 2024 · 3723 views
    This topic created in 884 days ago, the information mentioned may be changed or developed.

    我现在的情况是 我单独部署一个未集成数据库的情况下 部署到 vercel 可以正常访问 hello world

    但是我集成了数据库以后 我用的 orm 工具无论是 prisma 还是 sequelize 都会没法正常去访问

    我的疑惑点在于 vercel 可以去部署 nest+orm 的这种项目吗?

    如果可以是我哪里配置的不对呢?

    18 replies  •  2024-06-21 07:17:09 +08:00
    husinhu
    husinhu
    Jun 4, 2024
    1
    有没有一种可能是 next ?
    husinhu
    husinhu
    Jun 4, 2024
    2
    @husinhu 自评一下,原来还真有 nestjs ,哈哈
    yangg
    yangg
    Jun 4, 2024 via iPhone
    3
    prisma 肯定可以,请上错误信息
    mmdsun
    mmdsun
    Jun 5, 2024 via iPhone
    4
    @husinhu
    前端轮子太多了已经快分不清了。
    Next.js 、Nuxt.js 、Nest.js 。
    Next React 全栈框架,Nuxt 是 Vue 全栈,Nest 是后端框架。
    liwenka1
    liwenka1
    OP
    Jun 5, 2024
    5
    @yangg
    ```
    This Serverless Function has crashed.

    Your connection is working correctly.

    Vercel is working correctly.

    500: INTERNAL_SERVER_ERROR
    Code: FUNCTION_INVOCATION_FAILED
    ID: hnd1::npz54-1717550365607-554473530ff7
    ```
    这是我的 vercel.json
    ```
    {
    "builds": [
    {
    "src": "src/main.ts",
    "use": "@vercel/node"
    }
    ],
    "routes": [
    {
    "src": "/(.*)",
    "dest": "src/main.ts",
    "methods": ["GET", "POST", "PUT", "DELETE"]
    }
    ]
    }

    ```
    lshbosheth
    lshbosheth
    Jun 5, 2024
    6
    我连我服务器的 mysql 还是 vercel 的 pq 数据库 都可以,,,
    lshbosheth
    lshbosheth
    Jun 5, 2024
    7
    @2020583117 我感觉和这个配置没关系把 这个无非也就是类似入口文件的 作用 ?
    liwenka1
    liwenka1
    OP
    Jun 5, 2024
    8
    @lshbosheth 能详细讲解一下吗?我这边的情况是在我不使用 orm + 数据库的时候是正常的,但是使用以后就会出现上面的报错,我不太确定我部署 nest.js 的时候应该做哪些额外的配置或操作 /(ㄒoㄒ)/~~
    lshbosheth
    lshbosheth
    Jun 5, 2024
    9
    这是我 ormconfig 配置
    import { TypeOrmModuleOptions } from '@nestjs/typeorm';

    const VercelConfig: TypeOrmModuleOptions = {
    type: 'postgres',
    host: 'ep-aged-waterfall-13013279-pooler.us-east-1.postgres.vercel-storage.com',
    port: 5432,
    username: 'xxx',
    password: 'xxx',
    database: 'xxx',
    ssl: { rejectUnauthorized: false }, // For local development, consider removing this in production
    synchronize: true, // Automatically create database tables based on entities (set to false in production)
    logging: process.env.NODE_ENV === 'development' ? true : ['error'],
    entities: [__dirname + '/**/*.entity{.ts,.js}'],
    };

    const MySqlLocalConfig: TypeOrmModuleOptions = {
    type: 'mysql',
    host: 'xxx',
    port: 3306,
    username: 'root',
    password: 'xxx',
    database: 'xxx',
    synchronize: true,
    retryDelay: 500,
    retryAttempts: 10,
    autoLoadEntities: true,
    logging: process.env.NODE_ENV === 'development' ? true : ['error'],
    };

    export { VercelConfig, MySqlLocalConfig };
    具体我也不懂 哈哈哈
    直接 app.module 就用了 TypeOrmModule.forRoot(MySqlLocalConfig)
    然后 再 service 里直接整就完事了
    liwenka1
    liwenka1
    OP
    Jun 5, 2024
    10
    @lshbosheth 你没有去配置 vercel.json 这些吗?
    HeyCaptainJack
    HeyCaptainJack
    Jun 5, 2024
    11
    nestjs 可以用 railway 部署,vercel 主要针对 next.js 的
    liwenka1
    liwenka1
    OP
    Jun 5, 2024
    12
    @HeyCaptainJack railway 现在没有免费额度了吧?我好难受 /(ㄒoㄒ)/~~
    lshbosheth
    lshbosheth
    Jun 5, 2024
    13
    @2020583117 {
    "builds": [
    {
    "src": "src/main.ts",
    "use": "@vercel/node"
    }
    ],
    "routes": [
    { "src": "/(.*)", "dest": "src/main.ts" }
    ]
    }
    就这一点 我感觉这个就是个纯入口文件的作用把 和数据库没关系
    AEP203
    AEP203
    Jun 5, 2024
    14
    ```json
    {
    "$schema": "https://openapi.vercel.sh/vercel.json",
    "buildCommand": "pnpm build",
    "installCommand": "pnpm install",
    "outputDirectory": "packages/web/dist",
    "builds": [
    {
    "src": "package.json",
    "use": "@vercel/static-build",
    "config": {
    "zeroConfig": true,
    "installCommand": "pnpm install",
    "buildCommand": "pnpm build",
    "outputDirectory": "packages/web/dist"
    }
    },
    {
    "src": "packages/server/src/main.ts",
    "use": "@vercel/node"
    }
    ],
    "rewrites": [
    {
    "source": "api/(.*)",
    "destination": "packages/server/src/main.ts"
    }
    ]
    }
    ```

    这是我之前的配置,可以跑 nestjs ,但是原生的 .node 模块我没搞明白怎么配置,后来还是换阿里云了
    liwenka1
    liwenka1
    OP
    Jun 5, 2024
    15
    @lshbosheth 兄弟你仓库代码能给我看下不,或者给个联系方式具体请教一下你 我现在三个 orm 工具都用了一遍了 都是报错了 /(ㄒoㄒ)/~~
    lshbosheth
    lshbosheth
    Jun 6, 2024
    16
    @2020583117 我也是初学者 按照我之前 angular 经验和 chatgpt 搞得 。。。
    liwenka1
    liwenka1
    OP
    Jun 6, 2024
    17
    @lshbosheth 可能是我的数据库问题吧,我去排查一下吧,谢谢哥们回复了
    boogoogle
    boogoogle
    Jun 21, 2024
    18
    对啊,一般服务器到你的数据库不能直连,你得配置什么白名单,如果是 aws 的话,还有安全规则
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1767 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 16:59 · PVG 00:59 · LAX 08:59 · JFK 11:59
    ♥ Do have faith in what you're doing.