Client Static Hosting
It is possible to deploy each client and server separately in Frourio.
- npm
- yarn
The client is built with the following commands:
npm install
npm run build:client
It is your choice whether you want to start it with npm run start:client
or refer to it as out/
.
The client is built with the following commands:
yarn install
yarn run build:client
It is your choice whether you want to start it with yarn run start:client
or refer to it as out/
.
Below are some examples of typical static hosting services. Of course, you can deploy to services not listed here (including your own server), just give it a try!
GitHub Pages
Step 1. add GitHub Actions Workflow
If you selected GitHub Pages as the Static hosting service when you created the app, please SKIP to Step 2!
If you did not select GitHub Pages when you created the app, please refer to the following workflow to add a deployment workflow.
.github/workflows/deploy-client.yml
- npm
- yarn
name: Deploy client
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: |
if test -n '${{ secrets.GH_PAGES_BASE_PATH }}'; then
CLIENT_BASE_PATH='${{ secrets.GH_PAGES_BASE_PATH }}'
else
CLIENT_BASE_PATH="/$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')"
fi
echo "CLIENT_BASE_PATH=$CLIENT_BASE_PATH" >> $GITHUB_ENV
- uses: actions/cache@v2
id: client-npm-cache
with:
path: 'node_modules'
key: client-npm-${{ hashFiles('package-lock.json') }}
- uses: actions/cache@v2
id: server-npm-cache
with:
path: 'server/node_modules'
key: server-npm-${{ hashFiles('server/package-lock.json') }}
- run: npm install
if: steps.client-npm-cache.outputs.cache-hit != 'true'
- run: npm install --prefix server
if: steps.server-npm-cache.outputs.cache-hit != 'true'
- run: npm run build:client
env:
API_ORIGIN: ${{ secrets.API_ORIGIN }}
API_BASE_PATH: ${{ secrets.API_BASE_PATH }}
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./out
name: Deploy client
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: |
if test -n '${{ secrets.GH_PAGES_BASE_PATH }}'; then
CLIENT_BASE_PATH='${{ secrets.GH_PAGES_BASE_PATH }}'
else
CLIENT_BASE_PATH="/$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')"
fi
echo "CLIENT_BASE_PATH=$CLIENT_BASE_PATH" >> $GITHUB_ENV
- uses: actions/cache@v2
id: client-yarn-cache
with:
path: 'node_modules'
key: client-yarn-${{ hashFiles('yarn.lock') }}
- uses: actions/cache@v2
id: server-yarn-cache
with:
path: 'server/node_modules'
key: server-yarn-${{ hashFiles('server/yarn.lock') }}
- run: yarn install
if: steps.client-yarn-cache.outputs.cache-hit != 'true'
- run: yarn install --cwd server
if: steps.server-yarn-cache.outputs.cache-hit != 'true'
- run: yarn run build:client
env:
API_ORIGIN: ${{ secrets.API_ORIGIN }}
API_BASE_PATH: ${{ secrets.API_BASE_PATH }}
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./out
Step 2. add Secrets to Repository
Add following secrets to your GitHub repository.
API_ORIGIN
: API origin.
e.g.https://api.my-frourio-app.example
API_BASE_PATH
: API basepath.
e.g./api
GH_PAGES_BASE_PATH
(Optional): Client hosting basepath.- If omitted, GitHub repository name will be used. This is because GitHub hosts Pages at
github-username.github.io/repository-name
with default settings. - You can also use custom domain. When doing so, it is needed to use that basename. Set this
/
to host your client from root routing.
- If omitted, GitHub repository name will be used. This is because GitHub hosts Pages at
Vercel
- npm
- yarn
- Visit vercel.com and create new project.
- Set
BUILD COMMAND
tonpm run build:client
. - Add environment variables
API_BASE_PATH
andAPI_ORIGIN
.
- Visit vercel.com and create new project.
- Set
BUILD COMMAND
toyarn run build:client
. - Add environment variables
API_BASE_PATH
andAPI_ORIGIN
.
Netlify
- npm
- yarn
- Visit app.netlify.com and create new project.
- Go to Site Settings > Build & Deploy
a. Set Repository to your remote repository
b. Set Build command tonpm run build:client
c. Set Publish directory toout/
- Go to Site Settings > Build & Deploy > Environment
Add environment variablesAPI_ORIGIN
andAPI_BASE_PATH
- Visit app.netlify.com and create new project.
- Go to Site Settings > Build & Deploy
a. Set Repository to your remote repository
b. Set Build command toyarn run build:client
c. Set Publish directory toout/
- Go to Site Settings > Build & Deploy > Environment
Add environment variablesAPI_ORIGIN
andAPI_BASE_PATH