repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge dependabot/npm_and_yarn/examples/typescript/http-server-pool/fastify-cluster...
[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 da1066c4a7d997e044af5731596ca08c36a251ed..e04900ab2474afa7833c6bde6c5086030ab3882f 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,23
+1,25
@@
-import type { Server } from 'http'
-import type { AddressInfo } from 'net'
-import { ClusterWorker } from 'poolifier'
+import type { Server } from '
node:
http'
+import type { AddressInfo } from 'n
ode:n
et'
+
import express, { type Express, type Request, type Response } from 'express'
import express, { type Express, type Request, type Response } from 'express'
-import {
type WorkerData, type WorkerResponse } from './types.js
'
+import {
ClusterWorker } from 'poolifier
'
-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 { port } = workerData
!
const application: Express = express()
const application: Express = express()
@@
-30,18
+32,17
@@
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(port, () => {
console.info(
})
ExpressWorker.server = application.listen(port, () => {
console.info(
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`⚡️[express server]: Express server is started in cluster worker at http://localhost:${port}/`
)
})
return {
status: true,
`⚡️[express server]: Express server is started in cluster worker at http://localhost:${port}/`
)
})
return {
status: true,
- port: (ExpressWorker.server.address() as AddressInfo)
?.port ??
port
+ port: (ExpressWorker.server.address() as AddressInfo)
.
port
}
}
}
}