Main #5

Merged
Nikiroy78 merged 9 commits from main into laptop 2023-10-02 14:22:56 +03:00
12 changed files with 1487 additions and 0 deletions
Showing only changes of commit de5d0e599f - Show all commits

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/
ts.txt

7
api/index.js Normal file
View File

@ -0,0 +1,7 @@
const router = require('express').Router();
const config = require('../config-handler');
// if (config().logger_mode) router.use(require('./logger'));
// router.
module.exports = router;

0
api/v1/create-item.js Normal file
View File

0
api/v1/index.js Normal file
View File

6
config-handler.js Normal file
View File

@ -0,0 +1,6 @@
const fs = require('fs');
module.exports = () => {
const config = JSON.parse(fs.readFileSync("./config.json", { encoding : 'utf-8' }));
// Проверить конфиг на целостность
return config;
}

17
config.json Normal file
View File

@ -0,0 +1,17 @@
{
"address" : "127.0.0.1",
"port" : 8080,
"ssl" : {
"enabled" : false,
"public" : "",
"private" : ""
},
"database" : {
"port" : 5433,
"address" : "localhost",
"username" : "postgres",
"password" : "root"
},
"logger_mode" : true,
"logger_folder" : "./logger"
}

0
database.js Normal file
View File

24
logger.js Normal file
View File

@ -0,0 +1,24 @@
const config = require('./config-handler');
function log (date, req, ip, res) {
console.log(req);
let action = `HTTP ${req.httpVersion} ${req.method} ${req.url}
~~~~~~~~~
[HEADERS]
~~~~~~~~~
${Object.entries(req.headers).map(([header, value]) => header + ": " + value).join('\n')}`
console.log(res);
let response = '..';
console.log(`================================\nREPORT\n================================\nIP: ${ip}\n----------------\nACTION:\n----------------\n${action}\n----------------\nRESPONSE:\n----------------\n${response}`);
}
module.exports = async (req, res, next) => {
// console.log('ip', req.ip);
log(
new Date(),
req,
req.ip,
res
);
next();
};

1400
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"dependencies": {
"express": "^4.18.2",
"sequelize": "^6.33.0"
}
}

0
page-view.js Normal file
View File

25
server.js Normal file
View File

@ -0,0 +1,25 @@
const express = require('express');
const config = require('./config-handler');
const app = express();
app.use("/api", async (rq, rs, next) => next(), require('./api'));
app.get('/admin', async (req, res) => res.send('ok'));
app.use(!config().logger_mode ? async (rq, rs, next) => next() : require('./logger'), require('./api'));
// Подключение через HTTPS
let server;
if (!config().ssl.enabled) {
server = 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}`);
}
});