49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
const express = require('express');
|
|
const bodyHand = require('body');
|
|
const config = require('./config-handler');
|
|
|
|
const app = express();
|
|
|
|
app.use(async (req, res, next) => { // Для добавления оригинального тела запроса
|
|
const body = bodyHand(req, res, {
|
|
limit: 9999999999,
|
|
cache: false,
|
|
encoding: 'base64'
|
|
}, (err, body) => {
|
|
if (!err) {
|
|
req.byteBody = Buffer.from(body, 'base64');
|
|
}
|
|
else {
|
|
// console.log(err);
|
|
}
|
|
next();
|
|
});
|
|
});
|
|
|
|
app.use("/api", async (rq, rs, next) => next(), require('./api'));
|
|
|
|
app.get("/admin", async (req, res) => res.send('ok'));
|
|
|
|
if (config().logger_mode) app.use(require('./logger'), require('./api')); // Логгирование
|
|
|
|
// Подключение через HTTPS
|
|
let server;
|
|
if (!config().ssl.enabled) {
|
|
server = app;
|
|
}
|
|
else {
|
|
const https = require('https');
|
|
server = https.createServer({
|
|
cert : fs.readFileSync(config().ssl['public'], 'utf-8'),
|
|
key : fs.readFileSync(config().ssl['private'], 'utf-8')
|
|
}, app);
|
|
}
|
|
|
|
server.listen(config().port, config().address, async (err) => {
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
else {
|
|
console.log(`Kodex Muzic catalog runned at ${config().address}:${config().port}`);
|
|
}
|
|
}); |