All files / src/dev-server init.ts

94.44% Statements 17/18
33.33% Branches 1/3
100% Functions 2/2
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 241x 1x 1x 1x 1x     1x     8x 8x 16x 16x   8x 8x 8x 8x 8x 8x 8x    
import Fastify from "fastify";
import proxy from "./proxy";
import dirs from "./dirs";
import spa from "./spa";
import { responseLogger } from "./logger";
import type { DevServerConfig } from "./config";
 
export async function init(
  config: Partial<DevServerConfig> = {},
): Promise<any> {
  const server = Fastify(config.server as any);
  server.addHook("onSend", async (_: any, reply: any, payload: unknown) => {
    reply.header("X-Response-Time", reply.elapsedTime);
    return payload;
  });
  await server.register(proxy as any, config);
  await server.register(dirs as any, config);
  await server.register(spa as any, { ...config, prefix: config.basePath });
  await server.register(responseLogger as any, { silent: config.silent });
  Iif (config.extend) await server.register(config.extend as any, config);
  await server.ready();
  return server;
}