|
| 1 | +import PathToRegexpRouteMatcher from "@chubbyjs/chubbyjs-framework-router-path-to-regexp/dist/PathToRegexpRouteMatcher"; |
| 2 | +import PathToRegexpUrlGenerator from "@chubbyjs/chubbyjs-framework-router-path-to-regexp/dist/PathToRegexpUrlGenerator"; |
| 3 | +import ErrorMiddleware from "@chubbyjs/chubbyjs-framework/dist/Middleware/ErrorMiddleware"; |
| 4 | +import RouteMatcherMiddleware from "@chubbyjs/chubbyjs-framework/dist/Middleware/RouteMatcherMiddleware"; |
| 5 | +import ResponseFactory from "@chubbyjs/chubbyjs-http-message/dist/Factory/ResponseFactory"; |
| 6 | +import LaminasFactoryInterface from "@chubbyjs/chubbyjs-laminas-config/dist/LaminasFactoryInterface"; |
| 7 | +import PinoPsrLogger from "@chubbyjs/chubbyjs-pino-psr/dist/PinoPsrLogger"; |
| 8 | +import { createWriteStream, realpathSync, WriteStream } from "fs"; |
| 9 | +import { DestinationStream, LoggerOptions } from 'pino'; |
| 10 | +import CleanDirectoriesCommand from "../src/Command/CleanDirectoriesCommand"; |
| 11 | +import PingRequestHandler from "../src/RequestHandler/PingRequestHandler"; |
| 12 | +import CleanDirectoriesCommandFactory from "../src/ServiceFactory/Command/CleanDirectoriesCommandFactory"; |
| 13 | +import ErrorMiddlewareFactory from "../src/ServiceFactory/Framework/ErrorMiddlewareFactory"; |
| 14 | +import MiddlewaresFactory from "../src/ServiceFactory/Framework/MiddlewaresFactory"; |
| 15 | +import PathToRegexpRouteMatcherFactory from "../src/ServiceFactory/Framework/PathToRegexpRouteMatcherFactory"; |
| 16 | +import PathToRegexpUrlGeneratorFactory from "../src/ServiceFactory/Framework/PathToRegexpUrlGeneratorFactory"; |
| 17 | +import RouteMatcherMiddlewareFactory from "../src/ServiceFactory/Framework/RouteMatcherMiddlewareFactory"; |
| 18 | +import RoutesFactory from "../src/ServiceFactory/Framework/RoutesFactory"; |
| 19 | +import ResponseFactoryFactory from "../src/ServiceFactory/Http/ResponseFactoryFactory"; |
| 20 | +import PinoPsrLoggerFactory from "../src/ServiceFactory/Logger/PinoPsrLoggerFactory"; |
| 21 | +import PingRequestHandlerFactory from "../src/ServiceFactory/RequestHandler/PingRequestHandlerFactory"; |
| 22 | + |
| 23 | +export type Config = { |
| 24 | + debug: boolean, |
| 25 | + dependencies: { |
| 26 | + factories: Map<string, LaminasFactoryInterface>, |
| 27 | + }; |
| 28 | + directories: Map<string, string>, |
| 29 | + pino: { |
| 30 | + options: Omit<LoggerOptions, 'level'> & { level: 'fatal' | 'error' | 'warn' | 'info' | 'debug'; }, |
| 31 | + stream: DestinationStream, |
| 32 | + }, |
| 33 | +}; |
| 34 | + |
| 35 | +const rootDir = realpathSync(__dirname + '/..'); |
| 36 | + |
| 37 | +export default (env: string): Config => { |
| 38 | + const cacheDir = rootDir + '/var/cache/' + env; |
| 39 | + const logDir = rootDir + '/var/log'; |
| 40 | + |
| 41 | + let logStream: WriteStream | undefined; |
| 42 | + |
| 43 | + return { |
| 44 | + debug: false, |
| 45 | + dependencies: { |
| 46 | + factories: new Map<string, LaminasFactoryInterface>([ |
| 47 | + ['Middleware[]', MiddlewaresFactory], |
| 48 | + ['Routes', RoutesFactory], |
| 49 | + [CleanDirectoriesCommand.name, CleanDirectoriesCommandFactory], |
| 50 | + [ErrorMiddleware.name, ErrorMiddlewareFactory], |
| 51 | + [PathToRegexpRouteMatcher.name, PathToRegexpRouteMatcherFactory], |
| 52 | + [PathToRegexpUrlGenerator.name, PathToRegexpUrlGeneratorFactory], |
| 53 | + [PingRequestHandler.name, PingRequestHandlerFactory], |
| 54 | + [PinoPsrLogger.name, PinoPsrLoggerFactory], |
| 55 | + [ResponseFactory.name, ResponseFactoryFactory], |
| 56 | + [RouteMatcherMiddleware.name, RouteMatcherMiddlewareFactory], |
| 57 | + ]), |
| 58 | + }, |
| 59 | + directories: new Map([ |
| 60 | + ['cache', cacheDir], |
| 61 | + ['log', logDir], |
| 62 | + ]), |
| 63 | + pino: { |
| 64 | + options: { |
| 65 | + name: 'chubbyjs-framework-skeleton', |
| 66 | + level: 'info', |
| 67 | + }, |
| 68 | + stream: { |
| 69 | + write: (msg: string): void => { |
| 70 | + if (!logStream) { |
| 71 | + logStream = createWriteStream(logDir + '/' + env + '.log', { flags: 'a' }); |
| 72 | + } |
| 73 | + |
| 74 | + logStream.write(msg); |
| 75 | + } |
| 76 | + }, |
| 77 | + }, |
| 78 | + }; |
| 79 | +}; |
0 commit comments