migration to typescript
This commit is contained in:
parent
924000b084
commit
9fde77468a
41 changed files with 11952 additions and 10164 deletions
|
|
@ -4,7 +4,7 @@ description: How to setup the backend development environment
|
|||
|
||||
# Setup Development Environment
|
||||
|
||||
Follow these steps to setup the E-Learning Platform backend on your local machine.
|
||||
Follow these steps to setup the E-Learning Platform backend with TypeScript and TSOA on your local machine.
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -32,9 +32,77 @@ cd e-learning/Backend
|
|||
npm install
|
||||
```
|
||||
|
||||
// turbo
|
||||
Install TypeScript and TSOA:
|
||||
```bash
|
||||
npm install -D typescript @types/node @types/express ts-node nodemon
|
||||
npm install tsoa swagger-ui-express
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 3: Setup Environment Variables
|
||||
## Step 3: Initialize TypeScript
|
||||
|
||||
// turbo
|
||||
Create `tsconfig.json`:
|
||||
```bash
|
||||
npx tsc --init
|
||||
```
|
||||
|
||||
Update `tsconfig.json`:
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"lib": ["ES2020"],
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 4: Configure TSOA
|
||||
|
||||
Create `tsoa.json`:
|
||||
```json
|
||||
{
|
||||
"entryFile": "src/app.ts",
|
||||
"noImplicitAdditionalProperties": "throw-on-extras",
|
||||
"controllerPathGlobs": ["src/controllers/**/*.controller.ts"],
|
||||
"spec": {
|
||||
"outputDirectory": "public",
|
||||
"specVersion": 3,
|
||||
"securityDefinitions": {
|
||||
"jwt": {
|
||||
"type": "http",
|
||||
"scheme": "bearer",
|
||||
"bearerFormat": "JWT"
|
||||
}
|
||||
}
|
||||
},
|
||||
"routes": {
|
||||
"routesDir": "src/routes",
|
||||
"middleware": "express",
|
||||
"authenticationModule": "./src/middleware/auth.ts"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 5: Setup Environment Variables
|
||||
|
||||
Copy example env file:
|
||||
```bash
|
||||
|
|
@ -92,7 +160,7 @@ This starts:
|
|||
|
||||
---
|
||||
|
||||
## Step 5: Run Database Migrations
|
||||
## Step 6: Run Database Migrations
|
||||
|
||||
// turbo
|
||||
```bash
|
||||
|
|
@ -101,7 +169,7 @@ npx prisma migrate dev
|
|||
|
||||
---
|
||||
|
||||
## Step 6: Seed Database
|
||||
## Step 7: Seed Database
|
||||
|
||||
// turbo
|
||||
```bash
|
||||
|
|
@ -116,7 +184,20 @@ This creates:
|
|||
|
||||
---
|
||||
|
||||
## Step 7: Start Development Server
|
||||
## Step 8: Generate TSOA Routes
|
||||
|
||||
// turbo
|
||||
```bash
|
||||
npm run tsoa:gen
|
||||
```
|
||||
|
||||
This generates:
|
||||
- Routes in `src/routes/tsoa-routes.ts`
|
||||
- Swagger spec in `public/swagger.json`
|
||||
|
||||
---
|
||||
|
||||
## Step 9: Start Development Server
|
||||
|
||||
// turbo
|
||||
```bash
|
||||
|
|
@ -127,7 +208,7 @@ Server will start at http://localhost:4000
|
|||
|
||||
---
|
||||
|
||||
## Step 8: Verify Setup
|
||||
## Step 10: Verify Setup
|
||||
|
||||
// turbo
|
||||
Test health endpoint:
|
||||
|
|
@ -150,6 +231,7 @@ curl -X POST http://localhost:4000/api/auth/login \
|
|||
| Service | URL | Credentials |
|
||||
|---------|-----|-------------|
|
||||
| **Backend API** | http://localhost:4000 | - |
|
||||
| **API Docs (Swagger)** | http://localhost:4000/api-docs | - |
|
||||
| **MinIO Console** | http://localhost:9001 | admin / 12345678 |
|
||||
| **Mailhog UI** | http://localhost:8025 | - |
|
||||
| **Adminer** | http://localhost:8080 | postgres / 12345678 |
|
||||
|
|
@ -159,9 +241,15 @@ curl -X POST http://localhost:4000/api/auth/login \
|
|||
## Development Commands
|
||||
|
||||
```bash
|
||||
# Start dev server
|
||||
# Start dev server (TypeScript)
|
||||
npm run dev
|
||||
|
||||
# Build TypeScript
|
||||
npm run build
|
||||
|
||||
# Generate TSOA routes and Swagger
|
||||
npm run tsoa:gen
|
||||
|
||||
# Run tests
|
||||
npm test
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue