UNPKG

@practica/create-node-app

Version:

Create Node.js app that is packed with best practices AND strive for simplicity

25 lines (19 loc) 609 B
import fastify from 'fastify'; import { Server } from 'http'; import { RequestContext } from '../request-context-plugin'; let httpServer: Server; export const startTestServer = async (callbackOnRequest: () => void) => { const app = fastify({ logger: true }); app.register(RequestContext); app.get('/example-route', async (req, res) => { callbackOnRequest(); return res.status(200).send({ message: 'Hello, world!' }); }); await app.listen({ port: 3001 }); httpServer = app.server; }; export const stopTestServer = async () => { if (httpServer) { await httpServer.close(); } };