33 lines
1.4 KiB
JavaScript
33 lines
1.4 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const express_1 = __importDefault(require("express"));
|
|
const routes_1 = __importDefault(require("./routes"));
|
|
const http_1 = __importDefault(require("http"));
|
|
const websocket_1 = __importDefault(require("./websocket"));
|
|
const express_winston_1 = __importDefault(require("express-winston"));
|
|
const winston_1 = __importDefault(require("winston"));
|
|
class Api {
|
|
constructor(port) {
|
|
this.app = (0, express_1.default)();
|
|
this.app.use(express_winston_1.default.logger({
|
|
transports: [
|
|
new winston_1.default.transports.Console()
|
|
],
|
|
format: winston_1.default.format.combine(winston_1.default.format.colorize(), winston_1.default.format.cli()),
|
|
meta: true,
|
|
msg: "HTTP {{req.method}} {{req.url}}",
|
|
expressFormat: true,
|
|
colorize: true,
|
|
// ignoreRoute: function (req, res) { return false; } // optional: allows to skip some log messages based on request and/or response
|
|
}));
|
|
this.app.use("/api", routes_1.default);
|
|
this.server = http_1.default.createServer(this.app);
|
|
this.server.listen(port);
|
|
this.wss = new websocket_1.default(this.server);
|
|
}
|
|
}
|
|
exports.default = Api;
|