Skip to content

How to deploy an app you built with AI

Push the code to GitHub, connect the repository once, add the app's variables and press Deploy. Every push after that deploys by itself.

Audience
New to running a server
Last checked
Steps
7
Reading time
5 min

To put an app you built with an AI assistant online, push its code to GitHub, connect the repository in the control panel, add its variables and press Deploy. We detect the language and build it. Every push after that deploys by itself.

Code an assistant writes is ordinary code, so it runs like any other app. A few things that work on your computer need a change first: the port, the secrets and the data. Step 1 covers them.

On Hostsrc

App hosting is in beta. Order Hobby or Pro and Apps shows in the panel once your payment is confirmed. Final price, no VAT added.

Before you start

  • A Hostsrc account with App hosting turned on. It's in beta, so order Hobby or Pro first.
  • The app's code on your computer, in a Git repository.
  • A GitHub account.

Steps

  1. Step 1: Get the app ready to run on a server

    Check three things, or ask your assistant to check them:

    • The port. A web app must listen on 0.0.0.0 and on the port in the PORT variable, not on a fixed port on localhost. We set PORT for every web service. It is 8080 unless you change it.
    • The secrets. API keys and passwords must come from variables, not from the code. Keep them in a .env file that Git ignores, and list their names in a .env.example file.
    • The data. Each deploy starts from a fresh build of your code. Keep data you need in a database (step 6), not in a file in the app's folder.

    You can paste this to your assistant:

    Make this app ready to deploy: listen on 0.0.0.0 and on the port in the PORT environment variable, read every secret from environment variables, list their names in .env.example, and make sure .env is in .gitignore.

    Warning

    Never push a .env file with real keys. If one was pushed, change those keys, because anyone who can see the repository can read them.

  2. Step 2: Push the code to GitHub

    Create a repository on GitHub (external site, opens in a new tab), private or public, and push the code to it. If your assistant works in a terminal, it can run these commands for you. Use your own repository's address in the fifth line.

    git initgit add .git commit -m "First version"git branch -M maingit remote add origin https://github.com/you/your-app.gitgit push -u origin main
  3. Step 3: Connect the repository

    Sign in at control.hostsrc.com (opens in a new tab) with your Hostsrc account. In the header, switch to Apps.

    On Projects, press New, then Connect GitHub, and choose GitHub. GitHub asks which repositories to share: allow your app's repository. Back in Apps, press New again, choose GitHub Repository and pick it.

    The panel makes a project named after the repository, with the app in it as a service. The service opens on Variables. Nothing runs until you press Deploy in the next step.

  4. Step 4: Add the variables and deploy

    Copy each name and value from your .env file. On Variables, open Raw editor and paste them, one NAME=value per line. Or press New variable for each one. If the repository has a .env.example file, the panel lists its names under Suggested variables.

    Press Save variables, then Deploy. Saving alone doesn't start the app.

    OPENAI_API_KEY=paste-your-key-hereSESSION_SECRET=a-long-random-string

    Note

    You don't add PORT. We set it for you.

  5. Step 5: Give the app a web address

    A website or an API needs an address. Open Settings, then Networking. Under Public networking, press Generate Domain. The port is filled in from the one your app listens on. Check it, then press Generate.

    The app gets an address on up.hostsrc.app, such as your-app-production.up.hostsrc.app.

    To use your own domain, press Custom Domain, type the domain and press Add domain. The panel shows the DNS record to add at your domain's provider. Add it, then press Check now. The domain shows Live once HTTPS is set up.

    Note

    A bot or a background worker needs no address. It shows Private service, and that is right.

  6. Step 6: Add a database if the app needs one

    On the project, press New, then Database, and choose PostgreSQL. It shows up as a service named Postgres.

    Open your app's Variables and add DATABASE_URL with the value below. Typing ${{ in a value lists what you can use. Press Save variables, then Deploy.

    DATABASE_URL=${{Postgres.DATABASE_URL}}

    Note

    If your code reads another name, keep the value and change the name on the left. The database's Connect tab shows the reference too, under From another service.

  7. Step 7: Push changes and watch them go live

    From now on, every push to the repository's branch builds and deploys by itself. Open Deployments to watch it. A deployment shows BUILDING while we build the code and ACTIVE once the app runs. View logs shows the build step by step, and Logs shows what the app prints.

    If a change breaks something, open History on Deployments and open an earlier deployment. Choose Rollback to this in its menu and confirm with Roll back.

Troubleshooting

The deploy fails because the app is not ready

The app didn't answer on its port. Make it listen on 0.0.0.0 and on the port in PORT, then push again. If the panel says it listens on localhost only, change the host to 0.0.0.0. Many development servers take a --host option for this.

The build fails

Open the failed deployment and read its build logs. The last lines name the problem.

If the build can't tell how to start the app, set Start command in Settings, under Deploy, for example npm start or python main.py. Then press Deploy. If the repository has a Dockerfile in its top folder, we build from it instead.

The app works on my computer but not here

Open Logs and read the last lines. Two causes are common:

  • A variable is missing. Compare the names in your .env file with the ones on Variables.
  • The app still points at localhost for another service, such as a database. Use the reference from step 6 instead.

My repository isn't in the list

GitHub only shares the repositories you allowed. In the repository list, choose Configure repository access, allow the repository on GitHub, then come back and press New again.