【问题标题】:Vapor deploy to Heroku with log error code=H10 desc="App crashed" method=GETVapor 部署到 Heroku,日志错误代码=H10 desc="App crashed" method=GET
【发布时间】:2026-01-17 11:25:01
【问题描述】:

经过多次研究和尝试,我仍然无法解决问题。我使用Vapor Toolbox: 3.1.2 & Vapor Framework: 2.3.0 和 Swift 4.0.3(macos-high-sierra 上的 Xcode 9.2)来构建一个简单的网站(没有数据库)。但是在运行vapor heroku push 成功后,我尝试转到heroku dashboard 打开我的网站,但没有成功。我尝试运行 heroku logs 并得到 crashed 的结果:

2017-12-26T09:04:10.000000+00:00 app[api]: Build succeeded
2017-12-26T09:10:00.192686+00:00 heroku[web.1]: Process exited with status 127
2017-12-26T09:10:00.207462+00:00 heroku[web.1]: State changed from starting to crashed
2017-12-26T09:10:00.210981+00:00 heroku[web.1]: State changed from crashed to starting
2017-12-26T09:10:03.369454+00:00 heroku[web.1]: Starting process with command `leeswift --env=production --port=19489`
2017-12-26T09:10:00.072884+00:00 app[web.1]: bash: leeswift: command not found
2017-12-26T09:10:05.460027+00:00 app[web.1]: bash: leeswift: command not found
2017-12-26T09:10:05.560609+00:00 heroku[web.1]: Process exited with status 127
2017-12-26T09:10:05.594754+00:00 heroku[web.1]: State changed from starting to crashed
2017-12-26T09:11:28.858638+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=leeswift.herokuapp.com request_id=0eab887e-dba0-488e-b3f6-899de07898d6 fwd="118.69.108.38" dyno= connect= service= status=503 bytes= protocol=https

请帮我解决它。

【问题讨论】:

  • 您的问题解决了吗?它是恒定的还是间歇性的?

标签: heroku swift4 vapor


【解决方案1】:

我认为您的“Procfile”文件中有错误。例如,这是我的:

web: Run --env=production --workdir=./ --config:servers.default.port=$PORT

【讨论】:

  • echo web: 运行 serve --env production --hostname 0.0.0.0 --port $PORT
【解决方案2】:

bash: leeswift: 找不到命令

您的 heroku buildpack 无法找到为 steam 应用程序生成的可执行文件。这可能是应用程序名称/路径的问题。我还没有使用 heroku,但 Swift 会根据您的编译模式在 .build/release/<my-app>.build/debug/<my-app> 中生成它的可执行文件。

【讨论】:

    【解决方案3】:

    请按照以下步骤解决您的问题。

    如何借助 Vapor 框架创建 swift 后端 API。市场上也有另一个框架。但我们选择的是 swift vapor。

    让我们开始吧。

    在您的系统中安装蒸汽。

    步骤 1. 运行以下命令安装 vapor

    brew install vapor/tap/vapor-beta
    

    检查vapor是否安装或不运行以下命令。

    vapor-beta --help
    

    这些将是有用的蒸汽命令。

    仅当您在项目目录中时才使用命令。 你可以

    # Created vapor project
    vapor new myProjectName
    
    # Build vapor project 
    vapor build
    
    # Run vapor project
    vapor run 
    
    # You can configure Xcode. You should be inside created project directory. 
    vapor Xcode
    

    当您在项目文件中进行更改或添加新功能以进行更新时,您有以下命令。

    vapor Xcode
    

    您可以通过本地服务器测试 API 运行。输出将是“Hello World”

    curl http://localhost:8080/hello 
    

    =============================================PostgreSQL 安装== ================================================

    设置本地 PrortgeSQL。运行以下命令。

    brew install postgresql
    

    启动本地数据库服务器。运行以下命令

    pg_ctl -D /usr/local/var/postgres start
    

    停止本地数据库服务器。运行以下命令。

    pg_ctl -D /usr/local/var/postgres stop
    

    当您希望通过启动将 PostgreSQL 作为后台服务运行时,您可以使用 brew 服务器。运行以下命令。

    brew services start postgresql
    

    让我们以此来启动 Postgres。

    psql -d postgres
    

    通过运行以下命令创建数据库:

    create databas databaseName
    create databas ashi-app # Actual command 
    

    通过运行以下命令创建用户:- 通过运行以下命令授予该用户所需的权限。

    create user username
    create user ashi-app-user # Actual command
    
    grant all privileges on database databaseName to userName
    # Actual command
    grant all privileges on database ashi-app to ashi-app-user
    

    =============================================PostgreSQL 安装== ================================================

    ============================================部署新应用Heroku==================================================

    在没有数据库的 Heroku 上部署新的 swift vapor 应用。

    假设您已经创建了没有数据库的 Vapor 项目。

    第 1 步。在 cd MyApp 上导航。

    cd myApp
    # Actual command
    cd ashi-api
    

    第 2 步。在您的项目根目录中创建 swift 版本文件。在终端上运行。

    echo 5.1.3 > .swift-version
    

    步骤 3. 在您的项目根目录中创建 Procfile 文件。在终端下面运行。

    echo web: Run serve --env production --hostname 0.0.0.0 --port $PORT > Procfile 
    

    步骤 4. 添加文件 git 并通过以下命令提交

    git add .
    
    git commit -m ‘App Setup’
    

    第 5 步。您应该通过以下命令生成 linux 测试文件。

    swift test --generate-linuxmain
    

    步骤 6. 在 git 中通过以下命令再次添加修改。

    git add .
    
    git commit -m ‘Tests setup’
    

    第 7 步。登录 Heroku。在 heroku 上创建应用程序以进行部署时需要。所以我们登录了heruko。通过运行以下命令我们可以登录。

    heroku login
    

    第 8 步。一旦登录完成创建 heroku 应用程序。我们最喜欢的名称必须是 app-appname。

    heroku apps: create myAppName
    heroku apps: create ashi-api # Actual command
    

    第 9 步。使用应用程序添加 swift build pack。为了对此进行编译,我们必须添加 buildback。 Heroku 不支持 swift 的内置包。

    heroku buildpacks:set https://github.com/vapor-community/heroku-buildpack -a myproject
    
    # Actual command
    heroku buildpacks:set https://github.com/vapor-community/heroku-buildpack -a ashi-api
    

    第 10 步。在服务器上查找命令推送更改。

    git push heroku master
    

    现在您的应用和 API 可用于测试……

    ============================================部署新应用Heroku==================================================

    ======================使用已部署的应用程序和下一个版本的部署设置数据库============== =====================

    步骤 1. 进行数据库配置。用 postgreSQL 替换 sqlite 数据库。因为 Heroku 不支持 sqlite。

    在 App->configure.swift 中替换。并导入 Todo.h TodoController.h

    import FluentPostgreSQL
    
    // Configure a PostgreSQL database
        let postgreSQLConfig: PostgreSQLDatabaseConfig
        
        if let url = Environment.get("DATABASE_URL") {
          postgreSQLConfig = PostgreSQLDatabaseConfig(url: url)!
        } else {
          postgreSQLConfig = PostgreSQLDatabaseConfig(hostname: "localhost", username: "app_test")
        }
        let postgreSQL = PostgreSQLDatabase(config: postgreSQLConfig)
    
        // Register the configured PostreSQL database to the database config.
        var databases = DatabasesConfig()
        databases.add(database: postgreSQL, as: .psql)
        services.register(databases)
    

    第 2 步。通过运行使用 home-brew 安装 heroku 命令。

    brew tap heroic/brew && brew install heroku
    

    第三步,我们可以通过运行命令在app中添加postgreSQL。

    heroic addons:create heroic-postgresql:hobby-dev
    

    步骤 4. 通过运行以下命令在 git 中添加更新文件。

    git add .
    
    git commit -m ‘Added PostgreSQL file’
    

    第 5 步。在服务器上查找命令推送更改。

    git push heroku master
    

    第二个版本将可用于使用 postgreSQL 进行测试。

    ======================使用已部署的应用程序和下一个版本的部署设置数据库============== =====================

    【讨论】: