add files to project
This commit is contained in:
parent
b049ef1985
commit
de5d0e599f
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
ts.txt
|
7
api/index.js
Normal file
7
api/index.js
Normal 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
0
api/v1/create-item.js
Normal file
0
api/v1/index.js
Normal file
0
api/v1/index.js
Normal file
6
config-handler.js
Normal file
6
config-handler.js
Normal 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
17
config.json
Normal 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
0
database.js
Normal file
24
logger.js
Normal file
24
logger.js
Normal 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
1400
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
6
package.json
Normal file
6
package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"sequelize": "^6.33.0"
|
||||
}
|
||||
}
|
0
page-view.js
Normal file
0
page-view.js
Normal file
25
server.js
Normal file
25
server.js
Normal 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}`);
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user