mcfly/packages/fastify/serve.js
Ayo 970970fd32 feat: use fastify as server
- [x] implement server framework plugin config
- [x] new @mcflyjs/fastify package
- [x] update readme re: pivot & target state
- [x] new basic template

Reviewed-on: https://git.ayo.run/ayo/mcfly/pulls/2
Co-authored-by: Ayo <ayo@ayco.io>
Co-committed-by: Ayo <ayo@ayco.io>
2026-06-04 11:03:45 +00:00

22 lines
524 B
JavaScript

import Fastify from 'fastify'
import AutoLoad from '@fastify/autoload'
import path from 'node:path'
export default ({ rootDir, apiDir, logger, port }) => {
const server = Fastify()
const portNumber = port ?? 3000
server.register(AutoLoad, {
dir: path.join(rootDir, apiDir),
options: {
prefix: apiDir,
},
})
server
.listen({ port: portNumber })
.then(() => {
logger.log(`API now serving at http://localhost:${portNumber}${apiDir}`)
})
.catch((err) => logger.error(err))
}