UNPKG

nestjs-mvc-tools

Version:

NestJS MVC Tools is a small set of tools designed to help you get started more easily with traditional web development approaches in NestJS.

73 lines (72 loc) 3.41 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.NestMvcOptionsService = void 0; const common_1 = require("@nestjs/common"); const path_1 = require("path"); /** * Service for managing NestJS MVC configuration options. * Provides access to various module settings and configurations. */ let NestMvcOptionsService = class NestMvcOptionsService { // -------------------------------------------------------- // Methods // -------------------------------------------------------- constructor(options) { this.options = options; this.excludePaths = this.options.excludePaths ?? [ "/api", "/favicon.ico", "/.well-known/appspecific/com.chrome.devtools.json", ]; this.debug = this.options.debug ?? false; this.viewOptions = this.initViewOptions(this.options.view ?? {}); this.assetOptions = this.initAssetPipelineOptions(this.options.asset ?? {}); this.csrfOptions = this.initCsrfTokenOptions(this.options.csrf ?? {}); } initViewOptions(options) { return { rootDir: options?.rootDir ?? (0, path_1.join)(process.cwd(), "resources", "views"), disks: options?.disks ?? [], cache: options?.cache ?? false, helpers: options?.helpers ?? {}, globals: options?.globals ?? {}, globalsFactory: options?.globalsFactory, globalsInjects: options?.globalsInjects ?? [] }; } initAssetPipelineOptions(options) { return { mode: options?.mode ?? "development", staticAssetPrefix: options?.staticAssetPrefix ?? "/public", buildOutDir: options?.buildOutDir ?? (0, path_1.join)(process.cwd(), "resources", "public", "builds"), devServerUrl: options?.devServerUrl ?? "http://localhost:5173", }; } initCsrfTokenOptions(options) { return { enabled: options?.enabled ?? true, ignoredMethods: options?.ignoredMethods ?? ["GET", "HEAD", "OPTIONS"], saltLength: options?.saltLength ?? 8, secretLength: options?.secretLength ?? 18, }; } }; exports.NestMvcOptionsService = NestMvcOptionsService; exports.NestMvcOptionsService = NestMvcOptionsService = __decorate([ (0, common_1.Injectable)(), __param(0, (0, common_1.Inject)("NEST_MVC_OPTIONS")), __metadata("design:paramtypes", [Object]) ], NestMvcOptionsService);