Skip to content

Instantly share code, notes, and snippets.

@morintd

morintd/app.ts Secret

Created March 14, 2024 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morintd/334d908818d0d44e07aaa681c97df808 to your computer and use it in GitHub Desktop.
Save morintd/334d908818d0d44e07aaa681c97df808 to your computer and use it in GitHub Desktop.
import { Request, Response } from "express";
import cookieParser from "cookie-parser";
import express from "express";
import { TicTacToeController } from "../tic-tac-toe/tic-tac-toe.controller";
import { TicTacToeModule } from "../tic-tac-toe/tic-tac-toe.module";
import { Initialize } from "../tic-tac-toe/use-cases/initialize.use-case";
import { InMemoryBoardRepository } from "../tic-tac-toe/adapters/in-memory-board.repository";
import { Play } from "../tic-tac-toe/use-cases/play.use-case";
import { JumpTo } from "../tic-tac-toe/use-cases/jump-to.use-case";
function createApp() {
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
const repository = new InMemoryBoardRepository();
const initialize = new Initialize(repository);
const play = new Play(repository);
const jumpTo = new JumpTo(repository);
const module = new TicTacToeModule(
new TicTacToeController(initialize, play, jumpTo)
);
module.configure(app);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
app.use((error: any, _req: Request, res: Response) => {
console.log({ error, _req, res });
return res.status(error.status || 500).json(error.body);
});
return app;
}
export default createApp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment