Skip to content
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
8 changes: 5 additions & 3 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
- name: Generate Prisma Client
run: pnpm prisma generate

- name: Skip tests (no test script defined)
run: echo "⚠️ Aucun test défini, étape ignorée."
- name: Tests
run: pnpm run test

- name: Build app
run: pnpm build
Expand Down Expand Up @@ -109,6 +109,8 @@ jobs:
echo "🔧 Deploying on DEV..."
cd /home/baptiste/Dev/WPT/dev
docker-compose pull
docker rm -f wpt-dev_website || true
# stop + remove DEV containers ONLY (keeps volumes)
docker-compose down
# recreate containers, reusing existing volumes
docker-compose up -d --remove-orphans
echo "🚀 Deployed in DEV!"
9 changes: 4 additions & 5 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
- name: Generate Prisma Client
run: pnpm prisma generate

- name: Skip tests (no test script defined)
run: echo "⚠️ Aucun test défini, étape ignorée."
- name: Tests
run: pnpm run test

- name: Build app
run: pnpm build
Expand Down Expand Up @@ -105,7 +105,6 @@ jobs:
echo "🔧 Deploying on PROD..."
cd /home/baptiste/Dev/WPT/prod
docker-compose pull
docker rm -f wpt_website || true
docker-compose up -d --no-deps wpt_website
docker-compose down
docker-compose up -d --remove-orphans
echo "🚀 Deployed in PROD!"
echo "🚀 Deployed in PROD!"
52 changes: 52 additions & 0 deletions app/api/[uuid]/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { createRequestLogAction } from '@/lib/actions/request/create.actions'

export async function handleRequest(req: NextRequest, uuid: string) {
const method = req.method
const origin = req.headers.get('referer') || req.headers.get('origin') || null
const headers = Object.fromEntries(req.headers.entries())

const { searchParams } = new URL(req.url)
const queryParams = Object.fromEntries(searchParams.entries())

let body = null
let contentLength = 0

try {
if (method !== 'GET' && method !== 'HEAD') {
const rawBody = await req.arrayBuffer()
contentLength = rawBody.byteLength
try {
body = JSON.parse(new TextDecoder().decode(rawBody))
} catch {
body = null
}
}
} catch {
body = null
contentLength = 0
}

const ip =
(headers['x-forwarded-for'] as string)?.split(',')[0] ||
headers['x-real-ip'] ||
null
const userAgent = headers['user-agent'] || null

const status = await createRequestLogAction({
uuid,
method,
origin,
headers: JSON.stringify(headers),
queryParams: Object.keys(queryParams).length
? JSON.stringify(queryParams)
: null,
body: body ? JSON.stringify(body) : null,
ip,
userAgent,
contentLength,
})

return new NextResponse(undefined, { status })
}
52 changes: 2 additions & 50 deletions app/api/[uuid]/route.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,5 @@
import type { NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { createRequestLogAction } from '@/lib/actions/request/create.actions'

async function handleRequest(req: NextRequest, uuid: string) {
const method = req.method
const origin = req.headers.get('referer') || req.headers.get('origin') || null
const headers = Object.fromEntries(req.headers.entries())

const { searchParams } = new URL(req.url)
const queryParams = Object.fromEntries(searchParams.entries())

let body = null
let contentLength = 0

try {
if (method !== 'GET' && method !== 'HEAD') {
const rawBody = await req.arrayBuffer()
contentLength = rawBody.byteLength
try {
body = JSON.parse(new TextDecoder().decode(rawBody))
} catch {
body = null
}
}
} catch {
body = null
contentLength = 0
}

const ip =
headers['x-forwarded-for']?.split(',')[0] || headers['x-real-ip'] || null
const userAgent = headers['user-agent'] || null

const status = await createRequestLogAction({
uuid,
method,
origin,
headers: JSON.stringify(headers),
queryParams: Object.keys(queryParams).length
? JSON.stringify(queryParams)
: null,
body: body ? JSON.stringify(body) : null,
ip,
userAgent,
contentLength,
})

return new NextResponse(undefined, { status })
}
import { handleRequest } from './handler'

export async function GET(
req: NextRequest,
Expand Down Expand Up @@ -97,4 +49,4 @@ export async function HEAD(
) {
const { uuid } = await params
return handleRequest(req, uuid)
}
}
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
},
globals: {
'ts-jest': {
isolatedModules: true,
},
},
}
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"start": "next start",
"lint": "next lint",
"lint:fix": "next lint --fix",
"prisma:seed": "node prisma/seed.js"
"prisma:seed": "node prisma/seed.js",
"test": "jest --runInBand",
"test:watch": "jest --watch"
},
"dependencies": {
"@faker-js/faker": "^10.0.0",
Expand Down Expand Up @@ -55,13 +57,20 @@
"devDependencies": {
"@eslint/eslintrc": "^3.3.1",
"@tailwindcss/postcss": "^4.1.11",
"@types/express": "^5.0.5",
"@types/jest": "^30.0.0",
"@types/mime-types": "^3.0.1",
"@types/node": "^24.0.15",
"@types/react": "^19.1.8",
"@types/react-dom": "^19.1.6",
"@types/supertest": "^6.0.3",
"eslint": "^9.31.0",
"eslint-config-next": "15.4.2",
"express": "^5.1.0",
"jest": "^30.2.0",
"supertest": "^7.1.4",
"tailwindcss": "^4.1.11",
"ts-jest": "^29.4.5",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.8.3"
Expand Down
Loading
Loading