Start Vite a SPA with an API using API Platform and React !
The project is actually working for a development environment, it is NOT production ready for the moment !
- Symfony project with API Platform
- Vite project with the React plugin and using TypeScript
- PostgreSQL database
- Caddy server
- MailCatcher for debug mails and get a SMTP server
- A Makefile to automatise some process (run
make help
to list all available commands)
But you feel free to add or modify whatever you want !
-
Generate your project from GitHub and create two more empties projects
-
Clone your project and go inside
-
If you want to update references automatically into the main repository for each push on submodules, enable GitHub workflow.
-
Copy
.env.exemple
file into.env
and complete informations :
$ cp .env.exemple .env
- Run :
$ make init
This will :
- Create some git's aliases (
sdiff
,spush
,spull
) - Pull submodules
- Checkout submodules branches to master
- Run
composer install
intoback
folder - Run
yarn
intofront
folder - Build Docker Compose configuration
- Reset git configuration and change remote origin for
back
andfront
repositories :
$ cd back / front
$ rm -rf .git
$ git init
$ git remote add origin git@<repo_url>:<url>/<git_repository>.git
$ git add .
$ git commit -m 'Initial commit'
$ git push --force --set-upstream origin master
- Inside
.gitmodules
file, change theurl
options to accord to your empties projects :
[submodule "back"]
path = back
url = git@<repo_url>:<url>/<git_repository>.git
[submodule "front"]
path = front
url = git@<repo_url>:<url>/<git_repository>.git
-
Push content of both submodules (you feel free to partially or completely edit them before !)
-
You're done ! Just run :
$ make start
All is started and opened for you ! 🎉
Run when you're done :
$ make stop
-
Create a personal access token on GitHub with
read:org
andrepo
permissions with no expiration date -
For each project (main one and both submodules) do :
- Go to
Settings > Secrets > Actions
- Click on
New repository secret
- Set
CI_TOKEN
into theName
input - Paste your access token into the
Value
input - Click on
Add secret
to validate
- Go to
-
Run in a terminal where :
- $CI_TOKEN is your personal access token
- $PARENT_REPO is the name of the main repository (Ex :
Arkanii/symfovite
)
curl -X GET -H "Authorization: token $CI_TOKEN" https://api.github.com/repos/$PARENT_REPO/actions/workflows
-
Save the good workflow ID
-
In both submodules do:
- Go to
.github/workflows/submodule-notify-parent.yml
- Change environment variables :
- PARENT_REPO: The name of the main repository (Ex :
Arkanii/symfovite
) - PARENT_BRANCH: The main branch of your main repository
- WORKFLOW_ID: The ID you saved in step 4
- PARENT_REPO: The name of the main repository (Ex :
- Go to
-
Optional : Change the name, the email and commit message in
.github/workflows/submodules-sync.yml
-
Push all the files
-
And you're done ! 🎉
POSTGRES_DB
: Name of the database (Default:symfony
)POSTGRES_USER
: Name of the user (Default:symfony
)POSTGRES_PASSWORD
: User's password Please use a strong password (Default:symfony
)POSTGRES_PORT
: Port exposed by database container (Default:5432
)POSTGRES_VERSION
: Version of PostgreSQL (Default:13
)
PHP_VERSION
: PHP version (Default:8.1
)API_HTTP_PORT
: Port exposed by database container for browser connection in HTTP (Default:55999
)API_HTTPS_PORT
: Port exposed by database container for browser connection in HTTPS (Default:55995
)
VITE_HTTP_PORT
: Port exposed by database container for browser connection in HTTP (Default:80
)VITE_HTTPS_PORT
: Port exposed by database container for browser connection in HTTPS (Default:443
)
- Tech : Automation of step 5-6-7 when create a new project
- Docs : Change default plugin for Vite (Vue.js / Preact / etc.)
- Tech : Create all production environment
Created by Théo Frison, inspired and taken for some parts from this project.