We have gathered instructions for 4 different hosting solutions. There are som pros and cons with all so you have to pick the one suiting you. You can always host your Battlesnake in other places if you want.
- Replit. Supereasy to get started but you have to use a browser based IDE.
- Railway. You can develop on your machine and let Railway build your app when pushed to Github. But you need to give the Railway App access to your Github account.
- Render. You can develop locally just like Railway but you don't need to give access to you repo. The build is however very slow.
Replit is a free browser based hosting and IDE. You will edit your files directly in the browser with their built in IDE.
- Go to https://replit.com/ and create an account.
- Click "+ Create" to create a new Repl.
- Choose "Import from github".
- Paste "github.com/ola-gawell-dct/battlesnake-ts-starter" as GitHub URL.
- Choose Typescript from Language.
- Click "Import from GitHub".
- Click "Run" to build your project and launch the server. This will takes some time the first time since it needs to install all the npm dependencies. The next time will be much faster.
- When you see
Running Battlesnake at http://0.0.0.0:8000...
in the log the server is up and running. A small browser window will show up. - Copy the URL from the small browser window and use it in the next section. NOTE: It can somtimes take a while for the first request to the server to repond. The server might go into sleep mode after som inactivity so its good to call your url before the big finals.
Railway is a free browser based hosting.
- Go to https://github.com/ola-gawell-dct/battlesnake-ts-starter and fork the repo.
- Go to https://railway.app/ and click "login" an account to create a new account, user your Github account to log in.
- Click "+ New Project".
- Choose "Deploy from GitHub repo" and then “Configure GitHub App.
- Do the configuration and choose the forked repo.
- Click “+ Add variables” and enter a new variable “PORT” with value 6774 then press “+ Add” (Or whatever port is in the logs under the "Deployments tab)
- When you see
Running Battlesnake at http://0.0.0.0:6774...
in the log the server is up and running. - Go to “Settings” and press “Generate Domain”.
- Copy the URL from "Settings" under "Domain" and use it in the Battlesnake instructions section. (You might have to re-deploy after adding variable or generating domain if you can't ping the web server later from the Battlesnake website)
Notes
- Servers seems to be located in US-west, relevant when choosing engine region in the Battlesnake instructions section.
- Go to https://github.com/ola-gawell-dct/battlesnake-ts-starter and fork the repo and make it public.
- Go to https://dashboard.render.com/register.
- Create an account in any way you like.
- Select New Web Serivces.
- Paste the url to you forked repo from step 1 in the Public Git Repository field or choose to connect to you Github account (not tested).
- Press Continue.
- Name your project to anything you like.
- Choose Node as Environment.
- Press Create Web Service.
- The build will start immediately but will take some time. Every time you push changes to the git repository you need to press the Manual Deploy > Deploy latest commit.
NOTE: Heroku is not longer free to use. You can still use it but these instructions might not be complete anymore.
By following these instructions your server will be depolyed to Heroku. It is possible to host the server in any way you want as long as it is publicly accessible. The following instructions assumes that you want to use Heroku hosting.
If you don't want to install or use the Heroku CLI it is also possible to integrate Heroku with a Github repo, but that is not covered by this guide (https://devcenter.heroku.com/articles/github-integration).
-
Clone this repo.
-
Install Heroku CLI (might requiere a XCode and MacOS update on Mac) and create a Heroku account. https://devcenter.heroku.com/articles/heroku-cli
-
Run
heroku login
. -
Remove the git directory in this repo
rm -rf .git
. -
Initialize a fresh git repo
git init
. -
Commit all files
git add . git commit -m "Initial commit"
-
Create a heroku app
heroku create your-app-name
. -
Deploy your code
git push heroku main
.NOTE if you encounter an error messsge saying something the one below, you're trying to push a branch that doesn't exist.
error: src refspec master does not match any error: failed to push some refs to 'https://git.heroku.com/most-super-snake.git'
Change to the branch your're current using, for instance
master
. -
Verify by browsing to the URL printed by the last command.
remote: -----> Launching... remote: Released v3 remote: https://most-super-snake.herokuapp.com/ deployed to Heroku <---- THIS ONE
- Create a Battlesnake account at https://play.battlesnake.com/.
- Press "Create Battlesnake" on the Battlesnake site under "Battlesnakes".
- Choose a name and set the url to your url from last section.
- Choose Public battlesnake.
- Save
- Create a game and add your snake.
- Run it to verify that it respond to the call from Battlesnake.
Run jest test cases with:
npm run test
Install dependencies using npm
npm install
Start your Battlesnake
npm run start
You should see the following output once it is running
Running Battlesnake at http://0.0.0.0:8000
Open localhost:8000 in your browser and you should see
{"apiversion":"1","author":"","color":"#888888","head":"default","tail":"default"}
Install the Battlesnake CLI
- You can download compiled binaries here
- or install as a go package (requires Go 1.18 or higher)
Command to run a local game
battlesnake play -W 11 -H 11 --name 'TypeScript Starter Project' --url http://localhost:8000 -g solo --browser