Skip to content

Commit 5e16ade

Browse files
Added load balancing by clusters. Updated openapi doc
1 parent 88d0b33 commit 5e16ade

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

backend/api.yaml

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ paths:
3838
refreshToken:
3939
type: string
4040
example: <token>
41+
400:
42+
description: User already exists
43+
content:
44+
application/json:
45+
schema:
46+
type: object
47+
properties:
48+
status:
49+
type: integer
50+
example: 400
51+
message:
52+
type: string
53+
example: User with same email already exists.
54+
500:
55+
description: Unknown error
56+
content:
57+
application/json:
58+
schema:
59+
$ref: '#/components/schemas/UnknownErr'
4160

4261
/login:
4362
post:
@@ -68,7 +87,25 @@ paths:
6887
refreshToken:
6988
type: string
7089
example: <token>
71-
90+
404:
91+
description: User not found
92+
content:
93+
application/json:
94+
schema:
95+
type: object
96+
properties:
97+
status:
98+
type: integer
99+
example: 404
100+
message:
101+
type: string
102+
example: User not found or wrong password
103+
500:
104+
description: Unknown error
105+
content:
106+
application/json:
107+
schema:
108+
$ref: '#/components/schemas/UnknownErr'
72109
/api/events:
73110
get:
74111
summary: Get events for the authenticated user
@@ -89,6 +126,12 @@ paths:
89126
type: array
90127
items:
91128
$ref: '#/components/schemas/Events'
129+
500:
130+
description: Unknown error
131+
content:
132+
application/json:
133+
schema:
134+
$ref: '#/components/schemas/UnknownErr'
92135
post:
93136
summary: Create a new event
94137
security:
@@ -127,6 +170,12 @@ paths:
127170
message:
128171
type: string
129172
example: Event created
173+
500:
174+
description: Unknown error
175+
content:
176+
application/json:
177+
schema:
178+
$ref: '#/components/schemas/UnknownErr'
130179
delete:
131180
summary: Delete an event
132181
security:
@@ -151,6 +200,12 @@ paths:
151200
status:
152201
type: integer
153202
example: 204
203+
500:
204+
description: Unknown error
205+
content:
206+
application/json:
207+
schema:
208+
$ref: '#/components/schemas/UnknownErr'
154209
/api/logout:
155210
post:
156211
summary: Logout a user
@@ -177,6 +232,12 @@ paths:
177232
message:
178233
type: string
179234
example: User logged out
235+
500:
236+
description: Unknown error
237+
content:
238+
application/json:
239+
schema:
240+
$ref: '#/components/schemas/UnknownErr'
180241
/refreshToken:
181242
post:
182243
summary: Refresh access token
@@ -200,6 +261,12 @@ paths:
200261
example: 200
201262
accessToken:
202263
type: string
264+
500:
265+
description: Unknown error
266+
content:
267+
application/json:
268+
schema:
269+
$ref: '#/components/schemas/UnknownErr'
203270

204271
components:
205272
schemas:
@@ -246,6 +313,15 @@ components:
246313
userId:
247314
type: string
248315
format: objectId
316+
UnknownErr:
317+
type: object
318+
properties:
319+
status:
320+
type: integer
321+
example: 500
322+
message:
323+
type: string
324+
example: Unknown error
249325

250326
securitySchemes:
251327
bearerAuth:

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"module": "index.ts",
44
"type": "module",
55
"scripts": {
6-
"start": "bun run index.ts --env-file=.env",
6+
"start": "bun run start.ts --env-file=.env",
77
"compile": "bun build --compile index.ts",
88
"dev": "bun run --hot index.ts --env-file=.env"
99
},

backend/start.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {spawn} from 'bun'
2+
3+
const cpus = navigator.hardwareConcurrency
4+
const buns = new Array(cpus)
5+
6+
for(let i = 0;i<cpus;i++) {
7+
buns[i] = spawn({
8+
cmd: ['bun', 'index.ts'],
9+
stdout: 'inherit',
10+
stderr: 'inherit',
11+
stdin: 'inherit',
12+
})
13+
console.log(`Started process on pid ${buns[i].pid}`);
14+
15+
}
16+
17+
function kill() {
18+
for(const bun of buns) {
19+
bun.kill()
20+
}
21+
}
22+
23+
process.on('SIGINT', kill)
24+
process.on('exit', kill)

0 commit comments

Comments
 (0)