Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/backend ci & tests #80

Merged
merged 7 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/ci-back.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI Backend

on:
push:
branches: [ "develop", "main" ]
pull_request:
branches: [ "develop", "main" ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 20.x ]

defaults:
run:
working-directory: ./backend

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install pnpm
run: |
npm install -g pnpm

- name: Install dependencies
run: pnpm install

- name: Run Lint
run: pnpm lint

- name: Build Project
run: pnpm build

- name: Run Tests
run: pnpm test
3 changes: 3 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ tmp/
temp/
private.pem
public.pem

coverage
dist
29 changes: 15 additions & 14 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
# About

Backend WEB API application using:

- Express
- Typescript
- Postgres
- TypeORM
- pnpm

# Quick start

### Local

1. Install dependencies
```pnpm i```
`pnpm i`
- Install postgres:
- add to [config](./src/config/Config.ts) connection params
- set param at [db.ts DataSource](./src/db.ts)
```synchronize: true```

`synchronize: true`
- Generate RSA keys for JWT authentication _(terminal / git bash script below)_
```
mkdir -p src/config \
&& openssl genpkey -algorithm RSA -out src/config/private.pem -pkeyopt rsa_keygen_bits:2048 \
&& openssl rsa -pubout -in src/config/private.pem -out src/config/public.pem \
&& chmod 644 src/config/private.pem src/config/public.pem \
```
```
mkdir -p src/config \
&& openssl genpkey -algorithm RSA -out src/config/private.pem -pkeyopt rsa_keygen_bits:2048 \
&& openssl rsa -pubout -in src/config/private.pem -out src/config/public.pem \
&& chmod 644 src/config/private.pem src/config/public.pem \
```
2. Start backend:
- Production ready:
```pnpm start```
- Production ready:
`pnpm start`
- Development with hot reloading by Nodemon:
```pnpm dev```
`pnpm dev`
3. Listen [localhost:3000/](http://localhost:3000/)


# Contribution

- Reformat code
- Lint
- fix linter issues
- fix linter issues
- Test
- Commit and push branch
- Create PR and ask review
Expand Down
5 changes: 5 additions & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
};
15 changes: 11 additions & 4 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"description": "",
"main": "src/index.ts",
"scripts": {
"build": "tsc -p ./src/",
"build": "tsc -p .",
"start": "npx tsx ./src/index.ts",
"dev": "nodemon ./src/index.ts localhost 3000",
"lint": "eslint",
"lint:fix": "eslint --fix",
"prettify": "pnpm prettier . --write",
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest --coverage",
"typeorm": "typeorm-ts-node-esm"
},
"keywords": [],
Expand All @@ -19,11 +19,15 @@
"type": "module",
"dependencies": {
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/jsonwebtoken": "^9.0.6",
"@types/supertest": "^6.0.2",
"bcrypt": "^5.0.1",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.19.2",
"express-validator": "^7.0.0",
"jest": "^29.7.0",
"jsonwebtoken": "^9.0.2",
"libnpx": "^10.2.4",
"node": "21.6.1",
Expand All @@ -32,7 +36,9 @@
"pg": "^8.12.0",
"prettier": "^3.3.2",
"reflect-metadata": "^0.1.14",
"supertest": "^7.0.0",
"tpx": "0.0.1-beta.1",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"tsx": "^4.15.4",
"typeorm": "0.3.20",
Expand All @@ -42,11 +48,12 @@
"@eslint/js": "^9.4.0",
"@tsconfig/node-lts-strictest-esm": "^18.12.1",
"@types/bcrypt": "^5.0.2",
"@types/node": "^16.18.98",
"@types/cors": "^2.8.17",
"@types/node": "^20.14.8",
"eslint": "^8.57.0",
"globals": "^15.4.0",
"ts-node": "10.9.1",
"typescript": "4.5.2",
"typescript": "5.5.2",
"typescript-eslint": "^7.13.0"
},
"overrides": {
Expand Down
Loading
Loading