UNPKG

twitch-core

Version:
37 lines (36 loc) 1.41 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Server = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const morgan_1 = __importDefault(require("morgan")); const express_1 = __importDefault(require("express")); const CommandRoutes_1 = require("./routes/CommandRoutes"); class Server { constructor(client, port) { this.client = client; this.port = port; const logger = morgan_1.default('common', { stream: fs_1.default.createWriteStream(path_1.default.join(process.cwd(), 'log_server.log'), { flags: 'a' }) }); this.app = express_1.default(); this.app.use(logger); this.app.use(express_1.default.json()); this.app.use(express_1.default.urlencoded({ extended: true, inflate: false })); } registerRoutes() { this.app.use('/api/commands', new CommandRoutes_1.CommandRoutes(this.client).router); } start() { this.registerRoutes(); this.app.listen(this.port, () => { this.client.logger.info(`Server is running http://localhost:${this.port}`); }); } } exports.Server = Server;