我正在尝试从 CLI 在 Vercel ( https://vercel.com ,现在之前)部署一个 API(在 Node 中制作)。但是当我部署应用程序时,我打开站点,结果只是路径目录中的文件,而不是正在运行的应用程序。这是我的server.js
{
"name": "subtitles-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server.js",
"pre-deploy": "node deleteLastDeploy.js",
"deploy": "npm run pre-deploy && now --public && now alias",
"test": "echo \"Error: no test specified\" && exit 1"
}
"engines": {
"node": ">=6.9"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
//list of dependencies
}
}
要查看完整的 API:https://github.com/bitflix-official/subtitles-api
最佳答案
运行yarn global add now@latest
安装 CLI
now.json
归档并粘贴此 {
"version": 2,
"builds": [{
"src": "./server.js",
"use": "@now/node-server"
}],
"routes": [{"handle": "filesystem"},
{
"src": "/.*",
"dest": "server.js"
}
]
}
备注 : 更改 "src": "server.js",
&& "dest":"server.js"
到您的服务器入口文件。.gitignore
now
在 CLI 中进行部署。如果您要部署到生产环境,请使用
now --prod
CLI 中的命令进行部署这是我部署的示例服务器:https://vercel-example-server.now.sh .
关于javascript - 是否可以在 Vercel 中部署 NodeJs 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61808973/