V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
2020583117
V2EX  ›  Node.js

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

  •  
  •   2020583117 · 17 天前 · 1042 次点击

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

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

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

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

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