66 lines
2.8 KiB
JavaScript
66 lines
2.8 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.App = void 0;
|
|
const dotenv = __importStar(require("dotenv"));
|
|
const express_1 = __importDefault(require("express"));
|
|
const helmet_1 = __importDefault(require("helmet"));
|
|
const cors_1 = __importDefault(require("cors"));
|
|
const morgan_1 = __importDefault(require("morgan"));
|
|
const path = __importStar(require("path"));
|
|
const login_1 = require("./routes/login");
|
|
const index_1 = __importDefault(require("./routes/index"));
|
|
const constants_1 = require("./lib/constants");
|
|
dotenv.config();
|
|
class App {
|
|
constructor(NODE_ENV = 'development', PORT = 8080) {
|
|
const serverPort = process.env.PORT || PORT;
|
|
const sitePath = 'public';
|
|
const corsOptions = { credentials: false };
|
|
this.app = express_1.default();
|
|
this.app.use(morgan_1.default('dev'));
|
|
this.app.use(express_1.default.json());
|
|
this.app.use(express_1.default.urlencoded({ extended: false }));
|
|
this.app.use(cors_1.default(corsOptions));
|
|
this.app.use(helmet_1.default());
|
|
this.app.set('trust proxy', 1);
|
|
const login = login_1.Login(this.app);
|
|
this.app.get('/', (req, res) => {
|
|
console.log('p', path.join(process.cwd(), sitePath));
|
|
res.sendFile('index.html', { root: path.join(process.cwd(), sitePath) });
|
|
});
|
|
this.app.use(`${process.env.URL_PREFIX}`, index_1.default);
|
|
this.app.use('*', (req, res) => {
|
|
return res.status(404).json({
|
|
success: false,
|
|
message: constants_1.ERROR_MESSAGES.ENDPOINT_NOT_FOUND,
|
|
});
|
|
});
|
|
this.app.listen(serverPort, function () {
|
|
console.log('The server is running in port localhost: ', serverPort);
|
|
});
|
|
}
|
|
}
|
|
exports.App = App;
|
|
//# sourceMappingURL=server.js.map
|