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

23 天前
 2020583117

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

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

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

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

1167 次点击
所在节点    Node.js
18 条回复
husinhu
23 天前
有没有一种可能是 next ?
husinhu
23 天前
@husinhu 自评一下,原来还真有 nestjs ,哈哈
yangg
23 天前
prisma 肯定可以,请上错误信息
mmdsun
22 天前
@husinhu
前端轮子太多了已经快分不清了。
Next.js 、Nuxt.js 、Nest.js 。
Next React 全栈框架,Nuxt 是 Vue 全栈,Nest 是后端框架。
2020583117
22 天前
@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
22 天前
我连我服务器的 mysql 还是 vercel 的 pq 数据库 都可以,,,
lshbosheth
22 天前
@2020583117 我感觉和这个配置没关系把 这个无非也就是类似入口文件的 作用 ?
2020583117
22 天前
@lshbosheth 能详细讲解一下吗?我这边的情况是在我不使用 orm + 数据库的时候是正常的,但是使用以后就会出现上面的报错,我不太确定我部署 nest.js 的时候应该做哪些额外的配置或操作 /(ㄒoㄒ)/~~
lshbosheth
22 天前
这是我 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
22 天前
@lshbosheth 你没有去配置 vercel.json 这些吗?
HeyCaptainJack
22 天前
nestjs 可以用 railway 部署,vercel 主要针对 next.js 的
2020583117
22 天前
@HeyCaptainJack railway 现在没有免费额度了吧?我好难受 /(ㄒoㄒ)/~~
lshbosheth
22 天前
@2020583117 {
"builds": [
{
"src": "src/main.ts",
"use": "@vercel/node"
}
],
"routes": [
{ "src": "/(.*)", "dest": "src/main.ts" }
]
}
就这一点 我感觉这个就是个纯入口文件的作用把 和数据库没关系
AEP203
22 天前
```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
22 天前
@lshbosheth 兄弟你仓库代码能给我看下不,或者给个联系方式具体请教一下你 我现在三个 orm 工具都用了一遍了 都是报错了 /(ㄒoㄒ)/~~
lshbosheth
21 天前
@2020583117 我也是初学者 按照我之前 angular 经验和 chatgpt 搞得 。。。
2020583117
21 天前
@lshbosheth 可能是我的数据库问题吧,我去排查一下吧,谢谢哥们回复了
boogoogle
6 天前
对啊,一般服务器到你的数据库不能直连,你得配置什么白名单,如果是 aws 的话,还有安全规则

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1046807

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX