1 import { dirname
, extname
, join
} from
'node:path'
2 import { fileURLToPath
} from
'node:url'
3 import Fastify from
'fastify'
4 import { availableParallelism
} from
'poolifier'
5 import { fastifyPoolifier
} from
'./fastify-poolifier.js'
8 const fastify
= Fastify({
12 const workerFile
= join(
13 dirname(fileURLToPath(import.meta
.url
)),
14 `worker${extname(fileURLToPath(import.meta.url))}`
17 await fastify
.register(fastifyPoolifier
, {
20 maxWorkers
: availableParallelism(),
21 enableTasksQueue
: true,
25 errorHandler
: (e
: Error) => {
30 fastify
.all('/api/echo', async (request
, reply
) => {
31 await reply
.send((await fastify
.execute({ body
: request
.body
}, 'echo')).body
)
34 // fastify.get('/api/factorial/:number', async (request, reply) => {
35 // const { number } = request.params
36 // await reply.send((await fastify.execute({ body: { number } }, 'factorial')).body)
40 await fastify
.listen({ port
})
42 fastify
.log
.error(err
)