This project is the backend for the Secret Hitler game, intended to be deployed to Firebase Functions. It is designed to work with the frontend implemented using SvelteKit, deployed to Firebase Hosting.
Secret Hitler Svelte : https://github.com/touficbatache/SecretHitlerSvelte
git clone https://github.com/touficbatache/SecretHitlerFirebase.git
cd SecretHitlerFirebase
npm install
This API is supposed to be deployed to a Firebase project.
I - First, you will need to install the Firebase CLI using the following command:
npm install -g firebase-tools
Note: The -g
flag installs a package (here Firebase CLI) globally, which allows you
to call it from any command line on your local computer.
II - Then, you'll have to create a Firebase project with the following features turned on:
- Authentication
- Functions
- Realtime Database
and login:
firebase login
III - Link the project you just created by running the following command:
npm run link --project=[PROJECTNAME]
Inside to the functions/
directory, make sure to set the correct environment variable values for development
in .env
.
Then execute the following command, which listens to code changes when building and runs the Firebase Emulator locally:
npm run serve
The Emulator UI can be accessed using the URL shown in the terminal, usually http://localhost:4002/.
Inside to the functions/
directory, make sure to set the correct environment variable values for production
in .env.[PROJECTNAME]
, then deploy:
cd functions/
npm run deploy
http://127.0.0.1:5001/[project-id]/us-central1/api/[route]/
Request:
POST /newGame/
NO BODY
Response:
HTTP/1.1 201 Created
content-type: application/json
{ "code": "[GAMECODE]" }
Request:
POST /joinGame/
{
"code": "[GAMECODE]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
Request:
POST /startGame/
{
"code": "[GAMECODE]",
"hidePicsGameInfo": "[BOOLEAN]",
"skipLongIntro": "[BOOLEAN]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
Request:
POST /chooseChancellor/
{
"code": "[GAMECODE]",
"chancellorId": "[PLAYER_ID]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
Request:
POST /vote/
{
"code": "[GAMECODE]",
"vote": "[BOOLEAN]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
Request:
POST /presidentDiscardPolicy/
{
"code": "[GAMECODE]",
"policy": "[POLICY]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
Request:
POST /chancellorDiscardPolicy/
{
"code": "[GAMECODE]",
"policy": "[POLICY]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
Request:
POST /presidentialPower/
{
"code": "[GAMECODE]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{
"code": "[GAMECODE]",
"policies": "[POLICY],[POLICY],[POLICY]"
}
❗ Call again to continue game progress ❗
Request:
{
"code": "[GAMECODE]",
"player": "[PLAYER_ID]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
❗ Call again to continue game progress ❗
Request:
{
"code": "[GAMECODE]",
"player": "[PLAYER_ID]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
Request:
{
"code": "[GAMECODE]",
"player": "[PLAYER_ID]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
Request:
POST /askForVeto/
{
"code": "[GAMECODE]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
Request:
POST /answerVeto/
{
"code": "[GAMECODE]",
"refuseVeto": "[BOOLEAN]"
}
Response:
HTTP/1.1 200 OK
content-type: application/json
{ "code": "[GAMECODE]" }
Game will end automatically and a team will win depending on one of these conditions:
Liberal team:
- 5 liberal policies have been enacted, or
- Hitler is executed
Fascist team:
- 6 fascist policies have been enacted, or
- Hitler is elected Chancellor after 3 or more fascist policies are enacted
HTTP/1.1 401 Unauthorized
content-type: application/json
{ "message": "401 - Unauthorized" }
HTTP/1.1 403 Forbidden
content-type: application/json
{ "message": "403 - Forbidden" }
HTTP/1.1 422 Missing fields
content-type: application/json
{ "message": "422 - Missing fields" }
HTTP/1.1 452 Unknown
content-type: application/json
{ "message": "452 - Game not found" }
HTTP/1.1 453 Unknown
content-type: application/json
{ "message": "453 - Player already in game" }
HTTP/1.1 454 Unknown
content-type: application/json
{ "message": "454 - Player not in game" }
HTTP/1.1 455 Unknown
content-type: application/json
{ "message": "455 - Not enough players" }
HTTP/1.1 456 Unknown
content-type: application/json
{ "message": "456 - Game has already started" }
HTTP/1.1 457 Unknown
content-type: application/json
{ "message": "457 - Game progress can't be tampered with" }
HTTP/1.1 458 Unknown
content-type: application/json
{ "message": "458 - Player is ineligible" }