All files / src App.ts

86% Statements 43/50
92.3% Branches 12/13
100% Functions 1/1
86% Lines 43/50

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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 631x                 1x 21x   21x   21x 1x 1x 1x     21x 21x           21x 21x 3x 3x 3x 2x 2x 21x 21x 21x 21x 12x 12x 12x 2x 2x 12x 21x 21x 21x 21x 5x 5x 5x 4x 4x 5x 21x   21x 8x 21x   21x 21x  
import express from "express";
import { Env } from "@/Env";
import { POST as postMessage } from "@/handlers/api/line/v2/bot/message/push/route";
import { POST as postEvent } from "@/handlers/api/line/webhook/events/route";
import { GET as getNewMessage } from "@/handlers/api/line/webhook/messages/new/route";
import { DELETE as deleteMessage } from "@/handlers/api/line/webhook/messages/route";
import { Logger } from "@/Logger";
import { handleError } from "./handlers/error";
 
export function createApp(env: Env, logger: Logger): express.Express {
  const app = express();
 
  app.use(express.json());
 
  app.get("/", (_req, res, next) => {
    try {
      res.send(`running ${env.appName}`);
    } catch (err) {
      next(err);
    }
  });
  app.post("/api/line/v2/bot/message/push", async (req, res, next) => {
    try {
      await postMessage(env, logger, req, res);
    } catch (err) {
      next(err);
    }
  });
  app.post("/api/line/webhook/:channelId/events", async (req, res, next) => {
    try {
      await postEvent(env, logger, req, res);
    } catch (err) {
      next(err);
    }
  });
  app.get(
    "/api/line/webhook/:channelId/messages/new",
    async (req, res, next) => {
      try {
        await getNewMessage(env, logger, req, res);
      } catch (err) {
        next(err);
      }
    }
  );
  app.delete(
    "/api/line/webhook/:channelId/messages/:messageId",
    async (req, res, next) => {
      try {
        await deleteMessage(env, logger, req, res);
      } catch (err) {
        next(err);
      }
    }
  );
 
  app.use((err, _req, res, _next) => {
    handleError(logger, err, res);
  });
 
  return app;
}