@di-zed/yandex-smart-home
Version:
The Yandex Smart Home skills for the different device types.
61 lines (60 loc) • 2.19 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @author DiZed Team
* @copyright Copyright (c) DiZed Team (https://github.com/di-zed/)
*/
const dotenv_1 = __importDefault(require("dotenv"));
dotenv_1.default.config({ path: './.env' });
const express_1 = __importDefault(require("express"));
const fs_1 = __importDefault(require("fs"));
const https_1 = __importDefault(require("https"));
const index_1 = __importDefault(require("./index"));
process.on('unhandledRejection', (err) => {
console.log('ERROR! Unhandled Rejection! Shutting Down!');
console.log(err);
process.exit(1);
});
process.on('uncaughtException', (err) => {
console.log('ERROR! Uncaught Exception! Shutting Down!');
console.log(err);
process.exit(1);
});
const app = (0, express_1.default)();
(0, index_1.default)(app, {});
try {
let server;
const tlsKey = process.env.SERVER_TLS_KEY.trim();
const tlsCert = process.env.SERVER_TLS_CERT.trim();
if (tlsKey && tlsCert) {
const tlsPort = process.env.SERVER_TLS_CONTAINER_PORT ? parseInt(process.env.SERVER_TLS_CONTAINER_PORT, 10) : 443;
server = https_1.default
.createServer({
key: fs_1.default.readFileSync(tlsKey),
cert: fs_1.default.readFileSync(tlsCert),
}, app)
.listen(tlsPort, () => {
console.log(`The server is running on port ${tlsPort}.`);
});
}
else {
const port = process.env.SERVER_CONTAINER_PORT ? parseInt(process.env.SERVER_CONTAINER_PORT, 10) : 3000;
server = app.listen(port, () => {
console.log(`The server is running on port ${port}.`);
});
}
server.on('error', (err) => {
if (err.code === 'EADDRINUSE') {
console.log('ERROR! The server can NOT start. The address is already in use.');
}
else {
console.log('ERROR! The server can NOT start.', err);
}
});
}
catch (err) {
console.log('ERROR! The server can NOT start.', err);
}