- [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>
22 lines
524 B
JavaScript
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))
|
|
}
|