repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build: silence type warnings
[poolifier.git]
/
examples
/
typescript
/
http-server-pool
/
express-cluster
/
src
/
worker.ts
diff --git
a/examples/typescript/http-server-pool/express-cluster/src/worker.ts
b/examples/typescript/http-server-pool/express-cluster/src/worker.ts
index 27eda6f4d5f810442e8a4c3a083dfc56531da2e3..940503dfad3f241cceaefa3779060bd5f4afa1d8 100644
(file)
--- a/
examples/typescript/http-server-pool/express-cluster/src/worker.ts
+++ b/
examples/typescript/http-server-pool/express-cluster/src/worker.ts
@@
-1,22
+1,24
@@
-import type { Server } from 'http'
-import type { AddressInfo } from 'net'
+import type { Server } from '
node:
http'
+import type { AddressInfo } from 'n
ode:n
et'
import { ClusterWorker } from 'poolifier'
import express, { type Express, type Request, type Response } from 'express'
import { ClusterWorker } from 'poolifier'
import express, { type Express, type Request, type Response } from 'express'
-import { type WorkerData, type WorkerResponse } from './types.js'
-
-const factorial: (n: number) => number = (n) => {
- if (n === 0) {
- return 1
- }
- return factorial(n - 1) * n
-}
+import type { WorkerData, WorkerResponse } from './types.js'
class ExpressWorker extends ClusterWorker<WorkerData, WorkerResponse> {
private static server: Server
class ExpressWorker extends ClusterWorker<WorkerData, WorkerResponse> {
private static server: Server
+ private static readonly factorial = (n: number): number => {
+ if (n === 0) {
+ return 1
+ }
+ return ExpressWorker.factorial(n - 1) * n
+ }
+
private static readonly startExpress = (
workerData?: WorkerData
): WorkerResponse => {
private static readonly startExpress = (
workerData?: WorkerData
): WorkerResponse => {
+ const { port } = workerData as WorkerData
+
const application: Express = express()
// Parse only JSON requests body
const application: Express = express()
// Parse only JSON requests body
@@
-28,20
+30,18
@@
class ExpressWorker extends ClusterWorker<WorkerData, WorkerResponse> {
application.get('/api/factorial/:number', (req: Request, res: Response) => {
const { number } = req.params
application.get('/api/factorial/:number', (req: Request, res: Response) => {
const { number } = req.params
- res.send({ number: factorial(parseInt(number)) }).end()
+ res.send({ number:
ExpressWorker.
factorial(parseInt(number)) }).end()
})
})
- ExpressWorker.server = application.listen(
workerData?.
port, () => {
+ ExpressWorker.server = application.listen(port, () => {
console.info(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.info(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- `⚡️[express server]: Express server is started in cluster worker at http://localhost:${
workerData?.
port}/`
+ `⚡️[express server]: Express server is started in cluster worker at http://localhost:${port}/`
)
})
return {
status: true,
)
})
return {
status: true,
- port:
- (ExpressWorker.server.address() as AddressInfo)?.port ??
- workerData?.port
+ port: (ExpressWorker.server.address() as AddressInfo)?.port ?? port
}
}
}
}