大佬教程收集整理的这篇文章主要介绍了在 Heroku 上部署 typescsipt express 服务器,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在 heroku 平台上部署 node express 服务器,我的项目结构如下
├───build
│ ├───Models
│ │ └───DTOs
│ └───Routes
│ ├───admin
│ ├───auth
│ └───tweet
│ └───utils
├───node_modules
├───public
│ ├───images
│ └───styles
├───src
│ ├───Models
│ │ └───DTOs
│ └───Routes
│ ├───admin
│ ├───auth
│ └───tweet
│ ├───@types
│ └───utils
├───tests
│ └───Routes
│ └───auth
└───vIEws
这是我的 package.Json:
{
"repository": {
"url": "https://github.com/karafra/repost-data-bez-patosu.git","type": "git"
},"name": "long-tweets","version": "2.0.0","description": "API for matikng longer tweets","main": "index.Js","directorIEs": {
"test": "tests"
},"dependencIEs": {
"cookie-parser": "^1.4.5","dotenv": "^8.2.0","express": "^4.17.1","favicon": "0.0.2","firebase": "^8.2.10","pug": "^3.0.2","serve-favicon": "^2.5.0","ts-node": "^9.1.1","tslib": "^2.1.0","twitter-API-clIEnt": "^1.3.2","typescript": "^4.2.3","uuIDv4": "^6.2.6","nodemon": "^2.0.7","supertest": "^6.1.3","ts-jest": "^26.5.3"
},"devDependencIEs": {
"@firebase/analytics": "^0.6.4","@firebase/auth": "^0.16.4","@firebase/database": "^0.9.4","@firebase/firestore": "^2.1.7","@firebase/functions": "^0.6.2","@jest/types": "^26.6.2","@types/cookie-parser": "^1.4.2","@types/express": "^4.17.11","@types/jest": "^26.0.20","@types/mocha": "^8.2.1","@types/node": "^14.14.32","@types/node-fetch": "^2.5.8","@types/serve-favicon": "^2.5.2","firestore-jest-mock": "^0.9.0","jest": "^26.6.3","jest-junit": "^12.0.0","ts-jest": "^26.5.3","supertest": "^6.1.3"
},"scripts": {
"ts:watch": "tsc -w","ts:build": "tsc","watch": "concurrently \"npm run ts:watch\" \"npm run serve\"","watch:compile": "tsc -w","serve": "nodemon build/index.Js","serve:prod": "node build/index.Js","build": "npm run ts:build","start": "npm run build && npm run serve:prod","posTinstall": "npm run build","test": "jest --unhandled-rejections=Strict --colors --verbose --detectopenHandles","deploy": "git add . && git commit -m 'Heroku' && git pull && git push "
},"keywords": [
"twitter","twitlonger","bot","API"
],"author": "Karafra","license": "ISC","ENGInes": {
"node": "v14.9.0"
}
}
tsconfig.Json:
{
"compilerOptions": {
"module": "commonjs","Strict": true,"baseUrl": "./","outDir": "build","sourceMap": true,"removeComments": true,"experimentalDecorators": true,"target": "es6","Strictnullchecks": false,"emitDecoratorMetadata": true,"moduleResolution": "node","importHelpers": true,"types": [
"node","jest"
],"typeRoots": [
"node_modules/@types"
]
},"include": [
"./src/**/*.ts","./public"
],"exclude": [
"./src/public/"
]
}
procfile 为 web : npm start
,主 index.Js 文件为
import * as path from "path";
import * as express from "express";
import { Application } from "express";
import * as coockIEParser from "cookie-parser";
import { authRouter } from "./Routes/auth/Authresource";
import { tweetRouter } from "./Routes/tweet/Tweetresource";
import { adminRouter } from "./Routes/admin/adminConsoleresource";
import { tweetLongerRouter } from "./Routes/tweet/TweetLongerresource";
// Create express app
const app: Application = express()
// Use cookie parser
app.use(coockIEParser())
// Use body parser
app.use(express.Json())
// Use template ENGIne
app.set('vIEw ENGIne','pug');
app.set('vIEws',"./vIEws/");
app.use(express.static(path.join(__dirname,"public/")))
// Binding paths
app.use("/API",tweetLongerRouter)
app.use("/auth",authRouter)
app.use("/API",tweetRouter)
app.use("/admin",adminRouter)
//define index route
app.get("/",(req,res) => {
if (!(req.query && Object.keys(req.query).length === 0 && req.query.constructor === Object)) {
res.redirect(307,`/auth/valIDate/user/?email=${req.query.usernamE}&password=${req.query.passworD}`)
} else {
res.render("signUp");
}
})
//Get port from environment
const PORT: number = number(process.env.PORT) || 5000;
//Launch app on port from config file
app.Listen(PORT,() => {
console.log(`? App is running on http://localhost:${PORT}`)
})
当我在本地运行 heroku local
时一切正常,应用程序启动没有任何问题,但是当我尝试在 heroku 上部署时,构建运行正常但部署失败并显示 H10
错误代码。我尝试移动依赖项(从 devDependIEs 到依赖项再返回),我尝试运行在 stackoverflow 上找到的不同部署命令(因此有很多脚本),我尝试删除 dotenv.config() 调用,使用 ts-node 而不是部署tsc,删除所有环境变量并对其进行硬编码,使用构建文件夹推送代码并删除构建脚本。部署仍然失败并显示相同的 H10
错误代码。
Ps.: 这是来自heroku的日志
2021-03-16T22:46:16.000000+00:00 app[API]: Build started by user
email@email.com
2021-03-16T22:47:33.558208+00:00 app[API]: Deploy 985be468 by user
email@email.com
2021-03-16T22:47:33.558208+00:00 app[API]: Release v50 created by user
email@email.com
2021-03-16T22:47:34.811352+00:00 heroku[web.1]: State changed from crashed to starTing
2021-03-16T22:47:41.135283+00:00 heroku[web.1]: StarTing process with command `: npm start`
2021-03-16T22:47:42.000000+00:00 app[API]: Build succeeded
2021-03-16T22:47:43.245125+00:00 heroku[web.1]: Process exited with status 0
2021-03-16T22:47:43.317287+00:00 heroku[web.1]: State changed from starTing to crashed
2021-03-16T22:48:04.609680+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=myappname.heroku.com request_ID=6a7c6999-f493-468d-8d5d-f5654cadcb4c fwd="178.143.32.92" dyno= connect= service= status=503 bytes= protocol=https
2021-03-16T22:48:05.091732+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=myappname.heroku.com request_ID=418ab287-2b9d-4b40-a5e0-806c37bd1c11 fwd="178.143.32.92" dyno= connect= service= status=503 bytes= protocol=https
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的在 Heroku 上部署 typescsipt express 服务器全部内容,希望文章能够帮你解决在 Heroku 上部署 typescsipt express 服务器所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。