Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and review nano-server and Nanoservice Starter kit #171

Merged
merged 6 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"calt",
"mastmalize",
"mihandoost",
"nanoservice",
"preconnect",
"preload",
"tnum",
Expand Down
20 changes: 10 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
- **github/workflow:** schema detect ([b3b813c](https://github.com/AliMD/alwatr/commit/b3b813c45011afdc3e38dc7215f0f4beb8dcc1dd))
- **i18n:** load resources issue ([19b9e39](https://github.com/AliMD/alwatr/commit/19b9e39d5a415e60901c117be3f8f82d09ef8444))
- **logger:** refactor behavior of force ([7d9307b](https://github.com/AliMD/alwatr/commit/7d9307bb78523f3dae17b3bd80fa2fb47c90975f))
- **micro-server:** logger scope ([73dbf02](https://github.com/AliMD/alwatr/commit/73dbf029325169d900558e2361fec9fa4303e7e4))
- **nano-server:** logger scope ([73dbf02](https://github.com/AliMD/alwatr/commit/73dbf029325169d900558e2361fec9fa4303e7e4))
- **route:** remove default `200` status code ([12d9065](https://github.com/AliMD/alwatr/commit/12d9065c79ee7ca1acd458a20e9bd65b4554b8d2))
- **storage:** auto save request on set ([a1b671d](https://github.com/AliMD/alwatr/commit/a1b671d9beb8909d1fd89a1ffb7f80e1115b3cc3))
- **storage:** DocumentListStorage type issue ([f1c90b4](https://github.com/AliMD/alwatr/commit/f1c90b4b00a8696375e1a2f15d8b17378a33c7f2))
Expand All @@ -33,15 +33,15 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
- **jatabase:** impeliment class ([0fdd533](https://github.com/AliMD/alwatr/commit/0fdd533446943502c187d961ebfcbf872f7c15e1))
- **logger:** compatible with node.js ([7ee8b6d](https://github.com/AliMD/alwatr/commit/7ee8b6de3143e39c300345dec6864c9c56a4aae7))
- **logger:** node coloring support ([2b4aab6](https://github.com/AliMD/alwatr/commit/2b4aab655bc0707761587a7439de98bbd4ad0e08))
- **micro-server:** make `statusCode` in `ReplySuccessContent` optional ([fe836f4](https://github.com/AliMD/alwatr/commit/fe836f452566c541d25857df34c952b413690d23))
- **micro-server:** make new package ([2148dfc](https://github.com/AliMD/alwatr/commit/2148dfc910565f917d3cb8eb001cde08f2fc694d))
- **micro-server:** new class for handle server and connections ([62e33a3](https://github.com/AliMD/alwatr/commit/62e33a383b5220820f68f74020e04a7c5b390f0f))
- **microservice:** base app ([f8708cc](https://github.com/AliMD/alwatr/commit/f8708ccafe60ce89d635d43540ae1c627d0d8b55))
- **microservice:** esnext module ([8e9bd3d](https://github.com/AliMD/alwatr/commit/8e9bd3dd4fe16cfba41930633071965b32c5e7a8))
- **microservice:** home route ([851324e](https://github.com/AliMD/alwatr/commit/851324e328a5719fbc6702e72026e65df282db4f))
- **microservice:** load .env file ([ded93cb](https://github.com/AliMD/alwatr/commit/ded93cbe21071db48fddd468a8279640502c1fbb))
- **microservice:** make starter kit base files ([cbc2e47](https://github.com/AliMD/alwatr/commit/cbc2e478b1ad548134d4267c40548d1bd026bb62))
- **microservice:** new echo route ([de12548](https://github.com/AliMD/alwatr/commit/de125484c7bdeef40527c6cda0b9a1f0d83f5930))
- **nano-server:** make `statusCode` in `ReplySuccessContent` optional ([fe836f4](https://github.com/AliMD/alwatr/commit/fe836f452566c541d25857df34c952b413690d23))
- **nano-server:** make new package ([2148dfc](https://github.com/AliMD/alwatr/commit/2148dfc910565f917d3cb8eb001cde08f2fc694d))
- **nano-server:** new class for handle server and connections ([62e33a3](https://github.com/AliMD/alwatr/commit/62e33a383b5220820f68f74020e04a7c5b390f0f))
- **nanoservice:** base app ([f8708cc](https://github.com/AliMD/alwatr/commit/f8708ccafe60ce89d635d43540ae1c627d0d8b55))
- **nanoservice:** esnext module ([8e9bd3d](https://github.com/AliMD/alwatr/commit/8e9bd3dd4fe16cfba41930633071965b32c5e7a8))
- **nanoservice:** home route ([851324e](https://github.com/AliMD/alwatr/commit/851324e328a5719fbc6702e72026e65df282db4f))
- **nanoservice:** load .env file ([ded93cb](https://github.com/AliMD/alwatr/commit/ded93cbe21071db48fddd468a8279640502c1fbb))
- **nanoservice:** make starter kit base files ([cbc2e47](https://github.com/AliMD/alwatr/commit/cbc2e478b1ad548134d4267c40548d1bd026bb62))
- **nanoservice:** new echo route ([de12548](https://github.com/AliMD/alwatr/commit/de125484c7bdeef40527c6cda0b9a1f0d83f5930))

# [0.11.0](https://github.com/AliMD/alwatr/compare/v0.10.1...v0.11.0) (2022-04-16)

Expand Down
15 changes: 0 additions & 15 deletions packages/core/micro-server/CHANGELOG.md

This file was deleted.

3 changes: 0 additions & 3 deletions packages/core/micro-server/README.md

This file was deleted.

15 changes: 15 additions & 0 deletions packages/core/nano-server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.12.0](https://github.com/AliMD/alwatr/compare/v0.11.0...v0.12.0) (2022-07-22)

### Bug Fixes

- **nano-server:** logger scope ([73dbf02](https://github.com/AliMD/alwatr/commit/73dbf029325169d900558e2361fec9fa4303e7e4))

### Features

- **nano-server:** make `statusCode` in `ReplySuccessContent` optional ([fe836f4](https://github.com/AliMD/alwatr/commit/fe836f452566c541d25857df34c952b413690d23))
- **nano-server:** make new package ([2148dfc](https://github.com/AliMD/alwatr/commit/2148dfc910565f917d3cb8eb001cde08f2fc694d))
3 changes: 3 additions & 0 deletions packages/core/nano-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @alwatr/nano-server

Elegant powerful nodejs server for nanoservice use cases, written in tiny TypeScript module.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "@alwatr/micro-server",
"name": "@alwatr/nano-server",
"version": "0.12.0",
"description": "Elegant powerful nodejs server for microservice use cases, written in tiny TypeScript module.",
"description": "Elegant powerful nodejs server for nanoservice use cases, written in tiny TypeScript module.",
"keywords": [
"server",
"microservice",
"nanoservice",
"api",
"typescript",
"esm",
"alwatr"
],
"main": "micro-server.js",
"main": "nano-server.js",
"type": "module",
"types": "micro-server.d.ts",
"types": "nano-server.d.ts",
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
"license": "MIT",
"files": [
Expand All @@ -24,9 +24,9 @@
"repository": {
"type": "git",
"url": "https://github.com/AliMD/alwatr",
"directory": "packages/core/micro-server"
"directory": "packages/core/nano-server"
},
"homepage": "https://github.com/AliMD/alwatr/tree/main/packages/core/micro-server#readme",
"homepage": "https://github.com/AliMD/alwatr/tree/main/packages/core/nano-server#readme",
"bugs": {
"url": "https://github.com/AliMD/alwatr/issues"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import type {Methods, ReplyContent} from './type.js';
import type {IncomingMessage, ServerResponse} from 'http';

alwatrRegisteredList.push({
name: '@alwatr/micro-server',
name: '@alwatr/nano-server',
version: '{{ALWATR_VERSION}}',
});

export class AlwatrMicroServer {
protected logger = createLogger(`alwatr-micro-server:${this.port}`);
export class AlwatrNanoServer {
protected logger = createLogger(`alwatr-nano-server:${this.port}`);
protected server = createServer(this.handleRequest);

constructor(protected port: number, autoListen = true) {
Expand Down Expand Up @@ -58,7 +58,7 @@ export class AlwatrMicroServer {
connection.serverResponse.writeHead(200, {
'Content-Length': body.length,
'Content-Type': 'plain/text',
'Server': 'Alwatr MicroServer',
'Server': 'Alwatr NanoServer',
});
connection.serverResponse.end(body);
});
Expand Down Expand Up @@ -213,7 +213,7 @@ export class AlwatrConnection {
this.serverResponse.writeHead(content.statusCode ?? 200, {
'Content-Length': body.length,
'Content-Type': 'application/json',
'Server': 'Alwatr MicroServer',
'Server': 'Alwatr NanoServer',
});

this.serverResponse.write(body, 'utf8', (error: NodeJS.ErrnoException | null | undefined) => {
Expand Down
4 changes: 0 additions & 4 deletions packages/starter/microservice/.env.example

This file was deleted.

21 changes: 0 additions & 21 deletions packages/starter/microservice/CHANGELOG.md

This file was deleted.

5 changes: 0 additions & 5 deletions packages/starter/microservice/src/app.ts

This file was deleted.

21 changes: 21 additions & 0 deletions packages/starter/nanoservice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.12.0](https://github.com/AliMD/alwatr/compare/v0.11.0...v0.12.0) (2022-07-22)

### Bug Fixes

- **route:** remove default `200` status code ([12d9065](https://github.com/AliMD/alwatr/commit/12d9065c79ee7ca1acd458a20e9bd65b4554b8d2))

### Features

- **nano-server:** make new package ([2148dfc](https://github.com/AliMD/alwatr/commit/2148dfc910565f917d3cb8eb001cde08f2fc694d))
- **nano-server:** new class for handle server and connections ([62e33a3](https://github.com/AliMD/alwatr/commit/62e33a383b5220820f68f74020e04a7c5b390f0f))
- **nanoservice:** base app ([f8708cc](https://github.com/AliMD/alwatr/commit/f8708ccafe60ce89d635d43540ae1c627d0d8b55))
- **nanoservice:** esnext module ([8e9bd3d](https://github.com/AliMD/alwatr/commit/8e9bd3dd4fe16cfba41930633071965b32c5e7a8))
- **nanoservice:** home route ([851324e](https://github.com/AliMD/alwatr/commit/851324e328a5719fbc6702e72026e65df282db4f))
- **nanoservice:** load .env file ([ded93cb](https://github.com/AliMD/alwatr/commit/ded93cbe21071db48fddd468a8279640502c1fbb))
- **nanoservice:** make starter kit base files ([cbc2e47](https://github.com/AliMD/alwatr/commit/cbc2e478b1ad548134d4267c40548d1bd026bb62))
- **nanoservice:** new echo route ([de12548](https://github.com/AliMD/alwatr/commit/de125484c7bdeef40527c6cda0b9a1f0d83f5930))
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ Content-Type: application/json
### === Test all routes and errors ===

### Page Home
GET {{base}}/
GET {{base}}

### Page 404
### Page 404 (wrong path)
GET {{base}}/jafang

### Page 404 (wrong method)
POST {{base}}

### Page health
GET {{base}}/health
alimd marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "alwatr-microservice-starter",
"name": "alwatr-nanoservice-starter",
"version": "0.12.0",
"description": "Alwatr Microservice Starter Kit",
"description": "Alwatr Microservice/Nanoservice Starter Kit",
"type": "module",
"keywords": [
"microservice",
"nanoservice",
"api",
"typescript",
"esm",
Expand All @@ -16,9 +17,9 @@
"repository": {
"type": "git",
"url": "https://github.com/AliMD/alwatr",
"directory": "packages/starter/microservice"
"directory": "packages/starter/nanoservice"
},
"homepage": "https://github.com/AliMD/alwatr/tree/main/packages/starter/microservice#readme",
"homepage": "https://github.com/AliMD/alwatr/tree/main/packages/starter/nanoservice#readme",
"bugs": {
"url": "https://github.com/AliMD/alwatr/issues"
},
Expand All @@ -34,7 +35,8 @@
"start": "yarn serve",
"lint": "npm-run-all --sequential lint:*",
"lint:ts": "eslint **/*.ts",
"build": "tsc --build",
"build": "npm-run-all --sequential build:*",
"build:ts": "tsc --build",
"format": "npm-run-all --sequential format:prettier format:eslint",
"format:eslint": "eslint **/*.ts --fix",
"format:prettier": "prettier \"**/*.{html,json,md,ts}\" --ignore-path ./.eslintignore --write",
Expand All @@ -49,8 +51,7 @@
"dependencies": {
"@alwatr/logger": "^0.12.0",
"@alwatr/math": "^0.12.0",
"@alwatr/micro-server": "^0.12.0",
"dotenv": "^16.0.0"
"@alwatr/nano-server": "^0.12.0"
},
"devDependencies": {
"@types/node": "^18.0.6",
Expand Down
5 changes: 5 additions & 0 deletions packages/starter/nanoservice/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {AlwatrNanoServer} from '@alwatr/nano-server';

import {config} from './config.js';

export const app = new AlwatrNanoServer(config.port);
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import {createLogger} from '@alwatr/logger';
import {isNumber} from '@alwatr/math';
import {config as loadDotEnv} from 'dotenv';

loadDotEnv();

export const config = {
/* eslint-disable @typescript-eslint/no-non-null-assertion */
port: isNumber(process.env.PORT) ? +process.env.PORT! : 8000,
};

export const logger = createLogger('microservice');
export const logger = createLogger('nanoservice-starter');

logger.logProperty('config', config);
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import './route/echo.js';
import './route/home.js';
import {logger} from './config.js';

logger.logOther(`..:: Alwatr Microservice Starter Kit ::..`);
logger.logOther('..:: Alwatr Nanoservice Starter Kit ::..');
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {app} from '../app.js';

app.route('post', '/echo', async (connection) => {
const jsonBody = await connection.requireJsonBody();
if (jsonBody == null) return;
const bodyData = await connection.requireJsonBody();
if (bodyData == null) return;

connection.reply({
ok: true,
data: {
jsonBody,
...bodyData,
},
});
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {app} from '../app.js';

app.route('all', '/', async (connection) => {
app.route('get', '/', async (connection) => {
connection.reply({
ok: true,
data: {
app: 'Alwatr Microservice Starter Kit',
app: 'Alwatr Nanoservice Starter Kit',
message: 'Hello ;)',
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ESNext",
"target": "ES2022",
"module": "ESNext",
"lib": ["ESNext"],
// "allowJs": true,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
{"path": "./packages/core/router"},
{"path": "./packages/core/i18n"},
{"path": "./packages/core/math"},
{"path": "./packages/core/micro-server"},
{"path": "./packages/core/nano-server"},
{"path": "./packages/core/storage"},
{"path": "./demo"}
]
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2541,11 +2541,6 @@ dot-prop@^6.0.1:
dependencies:
is-obj "^2.0.0"

dotenv@^16.0.0:
version "16.0.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.1.tgz#8f8f9d94876c35dac989876a5d3a82a267fdce1d"
integrity sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==

dotenv@~10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
Expand Down