V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
liwenka1
V2EX  ›  Node.js

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

  •  
  •   liwenka1 · Jun 4, 2024 · 3107 views
    This topic created in 694 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
        1
    husinhu  
       Jun 4, 2024
    有没有一种可能是 next ?
    husinhu
        2
    husinhu  
       Jun 4, 2024
    @husinhu 自评一下,原来还真有 nestjs ,哈哈
    yangg
        3
    yangg  
       Jun 4, 2024 via iPhone
    prisma 肯定可以,请上错误信息
    mmdsun
        4
    mmdsun  
       Jun 5, 2024 via iPhone
    @husinhu
    前端轮子太多了已经快分不清了。
    Next.js 、Nuxt.js 、Nest.js 。
    Next React 全栈框架,Nuxt 是 Vue 全栈,Nest 是后端框架。
    liwenka1
        5
    liwenka1  
    OP
       Jun 5, 2024
    @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
        6
    lshbosheth  
       Jun 5, 2024
    我连我服务器的 mysql 还是 vercel 的 pq 数据库 都可以,,,
    lshbosheth
        7
    lshbosheth  
       Jun 5, 2024
    @2020583117 我感觉和这个配置没关系把 这个无非也就是类似入口文件的 作用 ?
    liwenka1
        8
    liwenka1  
    OP
       Jun 5, 2024
    @lshbosheth 能详细讲解一下吗?我这边的情况是在我不使用 orm + 数据库的时候是正常的,但是使用以后就会出现上面的报错,我不太确定我部署 nest.js 的时候应该做哪些额外的配置或操作 /(ㄒoㄒ)/~~
    lshbosheth
        9
    lshbosheth  
       Jun 5, 2024
    这是我 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
        10
    liwenka1  
    OP
       Jun 5, 2024
    @lshbosheth 你没有去配置 vercel.json 这些吗?
    HeyCaptainJack
        11
    HeyCaptainJack  
       Jun 5, 2024
    nestjs 可以用 railway 部署,vercel 主要针对 next.js 的
    liwenka1
        12
    liwenka1  
    OP
       Jun 5, 2024
    @HeyCaptainJack railway 现在没有免费额度了吧?我好难受 /(ㄒoㄒ)/~~
    lshbosheth
        13
    lshbosheth  
       Jun 5, 2024
    @2020583117 {
    "builds": [
    {
    "src": "src/main.ts",
    "use": "@vercel/node"
    }
    ],
    "routes": [
    { "src": "/(.*)", "dest": "src/main.ts" }
    ]
    }
    就这一点 我感觉这个就是个纯入口文件的作用把 和数据库没关系
    AEP203
        14
    AEP203  
       Jun 5, 2024
    ```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
        15
    liwenka1  
    OP
       Jun 5, 2024
    @lshbosheth 兄弟你仓库代码能给我看下不,或者给个联系方式具体请教一下你 我现在三个 orm 工具都用了一遍了 都是报错了 /(ㄒoㄒ)/~~
    lshbosheth
        16
    lshbosheth  
       Jun 6, 2024
    @2020583117 我也是初学者 按照我之前 angular 经验和 chatgpt 搞得 。。。
    liwenka1
        17
    liwenka1  
    OP
       Jun 6, 2024
    @lshbosheth 可能是我的数据库问题吧,我去排查一下吧,谢谢哥们回复了
    boogoogle
        18
    boogoogle  
       Jun 21, 2024
    对啊,一般服务器到你的数据库不能直连,你得配置什么白名单,如果是 aws 的话,还有安全规则
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1494 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 16:51 · PVG 00:51 · LAX 09:51 · JFK 12:51
    ♥ Do have faith in what you're doing.