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
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.0and on the port in thePORTvariable, not on a fixed port onlocalhost. We setPORTfor every web service. It is8080unless you change it. - The secrets. API keys and passwords must come from variables, not from the code. Keep them in a
.envfile that Git ignores, and list their names in a.env.examplefile. - 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
.envfile with real keys. If one was pushed, change those keys, because anyone who can see the repository can read them.- The port. A web app must listen on
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 mainStep 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.
Step 4: Add the variables and deploy
Copy each name and value from your
.envfile. On Variables, open Raw editor and paste them, oneNAME=valueper line. Or press New variable for each one. If the repository has a.env.examplefile, 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-stringNote
You don't add
PORT. We set it for you.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 asyour-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.
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_URLwith 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.
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.
Links
- GitHub (external site, opens in a new tab)
create the repository for your app
- Hostsrc control panel (opens in a new tab)
sign in, then switch to Apps
- App hosting
plans and prices, with a link to order each plan
App hosting
Hobby €5/month
Includes €5 of usage every month. In beta. Final price, no VAT added.
Choose a planDiscord
Ask other admins and our team.
Join our Discord (external site, opens in a new tab)Related guides
How to deploy a Next.js app from GitHub
Connect the repository and press Deploy. We run your build and start scripts, next build and next start, and every push to GitHub deploys by itself.
6 steps3 min readNew to running a server
How to host a discord.py bot
Put the bot in a GitHub repository with requirements.txt, read the token from a variable, connect the repository and press Deploy.
7 steps4 min readNew to running a server
How to put a Discord bot online with App hosting
Add the bot's repository, save its token as a variable and press Deploy. A bot needs no web address. App hosting is in beta.
8 steps6 min readNew to running a server