{"id":28563833,"url":"https://github.com/scorum/blog-admin-ws","last_synced_at":"2025-06-20T05:39:02.606Z","repository":{"id":295695108,"uuid":"988240004","full_name":"scorum/blog-admin-ws","owner":"scorum","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-26T22:07:07.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-10T13:08:46.870Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scorum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-22T08:59:58.000Z","updated_at":"2025-05-26T22:07:10.000Z","dependencies_parsed_at":"2025-05-26T23:31:21.938Z","dependency_job_id":null,"html_url":"https://github.com/scorum/blog-admin-ws","commit_stats":null,"previous_names":["scorum/blog-admin-ws"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/scorum/blog-admin-ws","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorum%2Fblog-admin-ws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorum%2Fblog-admin-ws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorum%2Fblog-admin-ws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorum%2Fblog-admin-ws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scorum","download_url":"https://codeload.github.com/scorum/blog-admin-ws/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorum%2Fblog-admin-ws/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260890581,"owners_count":23077863,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-10T13:08:45.442Z","updated_at":"2025-06-20T05:38:57.577Z","avatar_url":"https://github.com/scorum.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API for blog/admin\n\n  * Based on the Koa2\n  * Has a promisifyed MySQL lib with pool of connections\n  * Has MySQL migrations\n  * Has MySQL seeds\n  * Has .env file for the environment specific settings\n  * Has ESLint and Prettier integration\n  * Has the private /:privateUUID/health and /:privateUUID/version routes\n  * Has a middleware to validate the errors in the one place\n  * Has a pretty logger with date time, file path and colors\n\n## Installation\n\nJust clone the repository:\n\n```\ngit clone git@github.com:scorum/blog-admin-ws.git\n```\n\n## Usage\n\n### `.env` and `.env.default` files\n\nThe service uses `.env` file for the environment specific settings(HTTP port, MySQL pass, MySQL username and etc).\nWe are using [dotenv](https://www.npmjs.com/package/dotenv) lib to move variables from `.env` file to the `process.env`.\n`.env` file added to `.gitignore` to be sure not putting private data into the repository.\n`.env.default` this is template file for the developers and DevOps team to generate `.env` file with the right keys.\n\n#### `.env.default` structure\n\n```\n# ENVIRONMENT SETTINGS\nNODE_ENV = \"development\"\nHTTP_PORT = 3011\nALLOW_ORIGIN = \"*\"\nHEALTH_UUID = \"\"\n\nJWT_SECRET = \"\"\n\n# Database\nDB_HOST = \"\"\nDB_NAME = \"\"\nDB_PORT =\n\nDB_HOST = \"\"\nDB_PORT =\nDB_USER = \"\"\nDB_PASS = \"\"\nDB_NAME = \"\"\nDB_CONNECTION_LIMIT = 10\n\nREDIS_DB = \"\"\nREDIS_HOST = \"\"\nREDIS_PORT = \"\"\n```\n\n##### By default (look into `/helpers/env.js` file) `NODE_ENV` variable will be `production` to disable development logs and switch `koa` to the production mode. To override it just add `NODE_ENV=development` to your local or dev `.env` file.\n\n### ESLint and Prettier\n\nFor [eslint](https://eslint.org/) we are using the following configs: `airbnb-base` and plugings: `prettier`.\n\nWe are using [prettier](https://prettier.io/) for pretty code style in the team.\n\nTo run eslint use the following command:\n\n```\nnpm run lint\n```\n\n### Logger\n\nWe are using [Winston](https://github.com/winstonjs/winston) lib for the logs with some additional features.\nTo get logger just include the `get-logger` file from the `helpers` folder to your file and pass the prefix to the `getLogger` function. We reccomend to use the `__filename` for the prefix.\n\nExample:\n\n```\nconst logger = require('./helpers/get-logger')(__filename);\n\n/*\n ...\n*/\n\nlogger.info('App started successfully on the port %s', process.env.HTTP_PORT); // [2018-04-11T13:13:21.633Z] [info] /path/to/your/file.js - App started successfully on the port 3011\n```\n\n#### Log levels\n\n* `.warn` - yellow color\n* `.error` - red color\n* `.debug` - grey color\n* `.info` - green color\n\n### MySQL lib\n\nTo connect to the MySQL server we are using [MySQL driver](https://github.com/mysqljs/mysql).\nTo access MySQL connection instance from the routes you can use koa's state. Example:\n\n```\nconst now = await ctx.state.db.query('SELECT NOW()');\n```\n\nAlso, you can get new MySQL connection instance from the pool. Example:\n\n```\nconst mysql = require('./libs/mysql');\n\n/* .... */\n\nconst db = await mysql.getConnection();\n```\n\n#### MySQL lib API\n\n* `.getConnection` - gets new promisifyed connection instance(you can use `.queryAsync` instead of `.query`), returns Promise\n* `.end` - closes all connections, returns Promise\n\n### MySQL migrations\n\nFor MySQL migrations we are using [db-migrate](https://db-migrate.readthedocs.io/en/latest/) lib. To start migrations just run the following command:\n\n```\nnpm run migrate\n```\n\nYou create new migration with the following command `db-migrate create filename`.\n\n##### NOTE: Please read the [db-migrate](https://db-migrate.readthedocs.io/en/latest/) doc!\n\n### MySQL seeds\n\n```\nnode ./helpers/seeds.js\n```\n\n\n### Routes\n\nFor routing we using [koa-router](https://github.com/alexmingoia/koa-router) and for validation [koa-validate](https://github.com/RocksonZeta/koa-validate) libs. All routes placed in the `/controllers` folder and the main router is `/router.js`.\n\nBy default router has two private routes:\n\n* `/:privateUUID/health` - the health information for this service\n* `/:privateUUID/version` - the current version of the service\n\nTo access this router user needs to know `HEALTH UUID` set in the `.env` file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscorum%2Fblog-admin-ws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscorum%2Fblog-admin-ws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscorum%2Fblog-admin-ws/lists"}