mirror of
https://github.com/Redume/Kekkai.git
synced 2025-04-01 21:07:35 +03:00
Compare commits
8 commits
e2c513fe81
...
64185e7565
Author | SHA1 | Date | |
---|---|---|---|
64185e7565 | |||
f307644a8c | |||
f4475ae466 | |||
6cddaa53a8 | |||
c00dea8a81 | |||
1964fd333a | |||
dd24356e81 | |||
58e6ccfda6 |
10 changed files with 52 additions and 50 deletions
|
@ -9,7 +9,7 @@ import asyncpg
|
|||
|
||||
from utils.load_config import load_config
|
||||
|
||||
config = load_config('config.yaml')
|
||||
config = load_config('config.hjson')
|
||||
|
||||
async def create_pool() -> asyncpg.pool.Pool:
|
||||
"""
|
||||
|
|
|
@ -16,7 +16,7 @@ from routes import get_chart, get_chart_period
|
|||
from utils.load_config import load_config
|
||||
|
||||
app = FastAPI()
|
||||
config = load_config('config.yaml')
|
||||
config = load_config('config.hjson')
|
||||
|
||||
if not os.path.exists('../charts'):
|
||||
os.mkdir('../charts')
|
||||
|
@ -35,10 +35,10 @@ if __name__ == '__main__':
|
|||
port=3030,
|
||||
ssl_keyfile=
|
||||
config['server']['ssl']['private_key']
|
||||
if config['server']['ssl']['work']
|
||||
if config['server']['ssl']['enabled']
|
||||
else None,
|
||||
ssl_certfile=
|
||||
config['server']['ssl']['cert']
|
||||
if config['server']['ssl']['work']
|
||||
if config['server']['ssl']['enabled']
|
||||
else None
|
||||
)
|
||||
|
|
|
@ -9,7 +9,7 @@ from user_agents import parse as ua_parse
|
|||
|
||||
from utils.load_config import load_config
|
||||
|
||||
config = load_config('config.yaml')
|
||||
config = load_config('config.hjson')
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class PlausibleAnalytics:
|
||||
|
@ -23,7 +23,7 @@ class PlausibleAnalytics:
|
|||
async def __call__(self, request, call_next):
|
||||
response = await call_next(request)
|
||||
|
||||
if HTTPStatus(response.status_code).is_client_error or not config['analytics']['work']:
|
||||
if HTTPStatus(response.status_code).is_client_error or not config['analytics']['enabled']:
|
||||
return response
|
||||
|
||||
user_agent = request.headers.get('user-agent', 'unknown')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
matplotlib~=3.9.1
|
||||
PyYAML~=6.0.1
|
||||
hjson~=3.1.0
|
||||
uvicorn~=0.29.0
|
||||
fastapi[standard]~=0.115.2
|
||||
starlette~=0.40.0
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
# pylint: disable=R0801
|
||||
"""
|
||||
This module provides a function for loading a YAML configuration file.
|
||||
The function reads the file content and returns it as a Python dictionary.
|
||||
Parsing and converting HJSON config to JSON
|
||||
"""
|
||||
import yaml
|
||||
import hjson
|
||||
import json
|
||||
|
||||
def load_config(file_path: str) -> dict:
|
||||
"""
|
||||
Loads a YAML configuration file and returns its contents as a dictionary.
|
||||
Load an HJSON file, convert it to a JSON string with indentation,
|
||||
and return it.
|
||||
|
||||
This function opens the specified YAML file, parses its content, and
|
||||
returns it in dictionary format, making it accessible for use in
|
||||
the application.
|
||||
params: file_path (str): The path to the HJSON file.
|
||||
|
||||
:param file_path: The path to the YAML configuration file to be loaded.
|
||||
:return: A dictionary containing the parsed content of the YAML file.
|
||||
returns str: The JSON string formatted with indentation.
|
||||
"""
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
return yaml.safe_load(file)
|
||||
hjson_data = hjson.load(file)
|
||||
return json.loads(
|
||||
json.dumps(hjson_data, indent=4)
|
||||
)
|
||||
|
|
|
@ -24,7 +24,7 @@ services:
|
|||
- '3000:3000'
|
||||
volumes:
|
||||
- './CertSSL:/CertSSL'
|
||||
- './config.yaml:/config.yaml'
|
||||
- './config.hjson:/config.hjson'
|
||||
depends_on:
|
||||
- postgres
|
||||
|
||||
|
@ -36,7 +36,7 @@ services:
|
|||
- '3030:3030'
|
||||
volumes:
|
||||
- './CertSSL:/CertSSL'
|
||||
- './config.yaml:/config.yaml'
|
||||
- './config.hjson:/config.hjson'
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
@ -50,7 +50,7 @@ services:
|
|||
- '3050:3050'
|
||||
volumes:
|
||||
- './CertSSL:/CertSSL'
|
||||
- './config.yaml:/config.yaml'
|
||||
- './config.hjson:/config.hjson'
|
||||
|
||||
docs:
|
||||
build:
|
||||
|
@ -63,7 +63,7 @@ services:
|
|||
dockerfile: Dockerfile-collect-currency
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- './config.yaml:/config.yaml'
|
||||
- './config.hjson:/config.hjson'
|
||||
depends_on:
|
||||
- postgres
|
||||
|
||||
|
|
17
shared/config/package-lock.json
generated
17
shared/config/package-lock.json
generated
|
@ -9,19 +9,16 @@
|
|||
"version": "1.0.0",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"yaml": "^2.5.0"
|
||||
"hjson": "^3.2.2"
|
||||
}
|
||||
},
|
||||
"node_modules/yaml": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.0.tgz",
|
||||
"integrity": "sha512-2wWLbGbYDiSqqIKoPjar3MPgB94ErzCtrNE1FdqGuaO0pi2JGjmE8aW8TDZwzU7vuxcGRdL/4gPQwQ7hD5AMSw==",
|
||||
"license": "ISC",
|
||||
"node_modules/hjson": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/hjson/-/hjson-3.2.2.tgz",
|
||||
"integrity": "sha512-MkUeB0cTIlppeSsndgESkfFD21T2nXPRaBStLtf3cAYA2bVEFdXlodZB0TukwZiobPD1Ksax5DK4RTZeaXCI3Q==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"yaml": "bin.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
"hjson": "bin/hjson"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,6 @@
|
|||
"homepage": "https://github.com/Redume/Kekkai#readme",
|
||||
"description": "Config management service",
|
||||
"dependencies": {
|
||||
"yaml": "^2.5.0"
|
||||
"hjson": "^3.2.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
const fs = require('fs');
|
||||
const yaml = require('yaml');
|
||||
const hjson = require('hjson');
|
||||
|
||||
const config = () => {
|
||||
if (!fs.existsSync('../config.yaml')) return;
|
||||
if (!fs.existsSync('../config.hjson')) throw new Error('Config not found');
|
||||
|
||||
return yaml.parse(fs.readFileSync('../config.yaml', 'utf-8'));
|
||||
return hjson.parse(fs.readFileSync('../config.hjson', 'utf-8'));
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
|
|
33
web/main.js
33
web/main.js
|
@ -1,18 +1,24 @@
|
|||
const logger = require("../shared/logger");
|
||||
const config = require("../shared/config/src/main.js")();
|
||||
const logger = require('../shared/logger');
|
||||
const config = require('../shared/config/src/main.js')();
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("node:path");
|
||||
const fs = require('fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const fastify = require("fastify")({
|
||||
logger: config["server"]["log"]["print"] ? logger : false,
|
||||
...(config["server"]["ssl"]["work"]
|
||||
const fastify = require('fastify')({
|
||||
logger: config['server']['log']['level'] !== 'none' ? logger : false,
|
||||
...(config['server']['ssl']['enabled']
|
||||
? {
|
||||
https: {
|
||||
key: fs.readFileSync(config["server"]["ssl"]["private_key"], "utf8"),
|
||||
cert: fs.readFileSync(config["server"]["ssl"]["cert"], "utf8"),
|
||||
},
|
||||
}
|
||||
https: {
|
||||
key: fs.readFileSync(
|
||||
config['server']['ssl']['private_key'],
|
||||
'utf8',
|
||||
),
|
||||
cert: fs.readFileSync(
|
||||
config['server']['ssl']['cert'],
|
||||
'utf8',
|
||||
),
|
||||
},
|
||||
}
|
||||
: false),
|
||||
});
|
||||
|
||||
|
@ -23,11 +29,10 @@ fastify.register(require('@fastify/static'), {
|
|||
|
||||
fastify.register(require('./routes/home.js'));
|
||||
|
||||
|
||||
fastify.listen(
|
||||
{
|
||||
port: 3050,
|
||||
host: config["server"]["host"] ? config["server"]["host"] : "localhost",
|
||||
host: config['server']['host'] ? config['server']['host'] : 'localhost',
|
||||
},
|
||||
(err) => {
|
||||
if (err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue