-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
3,842 additions
and
2,529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Deploy to Firebase Hosting on merge (dev) | ||
'on': | ||
push: | ||
branches: | ||
- develop | ||
jobs: | ||
build_and_deploy: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
environment: | ||
- lszt_test | ||
- lszm_test | ||
- lspv_test | ||
environment: ${{ matrix.environment }} | ||
steps: | ||
- run: echo 'Running deplyoment for project ${{ vars.PROJECT }}' | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 10 | ||
- run: npm ci | ||
- run: npm run build --project=${{ vars.PROJECT }} | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- uses: w9jds/setup-firebase@main | ||
with: | ||
project_id: ${{ vars.FIREBASE_PROJECT }} | ||
tools-version: 13 | ||
firebase_token: ${{ secrets.FIREBASE_TOKEN }} | ||
- run: firebase target:apply database main ${{ vars.FIREBASE_PROJECT }} | ||
- run: firebase deploy --only hosting,database:main | ||
build_and_deploy_functions: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
environment: | ||
- lszt_test | ||
- lszm_test | ||
- lspv_test | ||
environment: ${{ matrix.environment }} | ||
steps: | ||
- run: echo 'Running functions deplyoment for project ${{ vars.PROJECT }}' | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- uses: w9jds/setup-firebase@main | ||
with: | ||
project_id: ${{ vars.FIREBASE_PROJECT }} | ||
tools-version: 13 | ||
firebase_token: ${{ secrets.FIREBASE_TOKEN }} | ||
- run: cd functions && npm ci && cd .. | ||
- run: firebase deploy --only functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Build and test on PR | ||
'on': pull_request | ||
jobs: | ||
build: | ||
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 10 | ||
- run: npm ci | ||
#- run: npm test TODO reenable tests when fixed | ||
- run: npm run build | ||
build_functions: | ||
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: cd functions && npm ci && cd .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,14 @@ | |
|
||
### Getting Started | ||
|
||
#### Required Node Versions | ||
|
||
Node Version for building the app: 10 | ||
|
||
Node Version for deploying to Firebase and for the cloud functions: 20 | ||
|
||
#### Start locally | ||
|
||
``` | ||
$ npm install | ||
$ npm start [--project={PROJECT_NAME}] | ||
|
@@ -52,13 +60,46 @@ $ npm run build:prod [--project={PROJECT_NAME}] | |
|
||
#### Push to Firebase | ||
|
||
Prerequisites: Firebase Tools must be installed (`npm install -g firebase-tools`). | ||
Node version for this step: 20 | ||
|
||
Prerequisites: Firebase Tools must be installed (`npm install -g firebase-tools@13`). | ||
|
||
**Caution:** Ensure that you have selected the right Firebase project (list all projects by typing `firebase list` and change it if necessary (with `firebase use`)). | ||
|
||
##### Set up env | ||
|
||
Set the realtime database name for the cloud functions: | ||
|
||
``` | ||
$ firebase deploy | ||
firebase functions:config:set rtdb.instance={RTDB NAME} | ||
``` | ||
|
||
(e.g. `firebase functions:config:set rtdb.instance=lszt-test`) | ||
|
||
##### Deploy app | ||
|
||
Before executing this command, make sure the correct project was built using the Node version | ||
mentioned at the beginning of this document. | ||
|
||
``` | ||
$ firebase target:apply database main {RTDB NAME} | ||
$ firebase deploy --only hosting,database:main | ||
``` | ||
|
||
(e.g. `lszt-test` for `{RTDB NAME}`) | ||
|
||
##### Deploy cloud functions | ||
|
||
Use the following commands to deploy the cloud functions. | ||
|
||
Before executing these commands, make sure you selected the correct Node version for the cloud | ||
functions, which is mentioned at the beginning of this document. | ||
|
||
``` | ||
$ cd functions && npm ci && cd .. | ||
$ firebase deploy --only functions | ||
``` | ||
|
||
## Cloud functions | ||
|
||
### `auth` | ||
|
@@ -142,3 +183,42 @@ Returns (example): | |
``` | ||
|
||
If no status is set, `{}` is returned. | ||
|
||
#### Import users #### | ||
|
||
##### Request ##### | ||
|
||
POST an array of users to this endpoint to sync the users list. | ||
|
||
New users are added, existing ones are updated, and those which are saved in the database, but not present in the given | ||
users array are removed from the database. | ||
|
||
Example payload: | ||
``` | ||
POST /api/users/import | ||
{ | ||
"users": [ | ||
{ | ||
"memberNr": "48434", | ||
"firstname": "John", | ||
"lastname": "Doe", | ||
"phone": "+41791234567", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"memberNr": "30443", | ||
"firstname": "Jane", | ||
"lastname": "Smith", | ||
"phone": "+41791234568", | ||
"email": "[email protected]" | ||
}, | ||
... | ||
] | ||
} | ||
``` | ||
|
||
##### Auth ##### | ||
|
||
This endpoint requires a Basic Auth header (username and password to use set in the function config: | ||
`api.serviceuser.username` and `api.serviceuser.password`). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
{ | ||
"database": { | ||
"database": [{ | ||
"target": "main", | ||
"rules": "build/firebase-rules.json" | ||
}, | ||
}], | ||
"hosting": { | ||
"public": "build", | ||
"ignore": [ | ||
"firebase-rules.json" | ||
], | ||
"rewrites": [{ | ||
"source": "/api/**", | ||
"function": "api" | ||
}] | ||
}, | ||
"functions": { | ||
"source": "functions" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const functions = require('firebase-functions') | ||
|
||
const config = functions.config(); | ||
|
||
const basicAuth = (req, res, next) => { | ||
if (!config.api || !config.api.serviceuser || !config.api.serviceuser.username || !config.api.serviceuser.password) { | ||
console.info( | ||
"Set configuration properties `api.serviceuser.username` and `api.serviceuser.password` for the API auth" | ||
) | ||
res.status(401).send('Unauthorized') | ||
return | ||
} | ||
|
||
const authHeader = req.headers.authorization || '' | ||
const [type, credentials] = authHeader.split(' ') | ||
|
||
if (type === 'Basic' && credentials) { | ||
const decoded = Buffer.from(credentials, 'base64').toString('utf-8') | ||
const [username, password] = decoded.split(':') | ||
|
||
if (username === config.api.serviceuser.username && password === config.api.serviceuser.password) { | ||
return next() | ||
} | ||
} | ||
|
||
res.status(401).send('Unauthorized') | ||
} | ||
|
||
module.exports = basicAuth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.