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

feat(form): new micro service #648

Merged
merged 11 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 16 additions & 9 deletions .github/workflows/publish-alwatr-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,37 @@ jobs:
fail-fast: false
matrix:
include:
- image: storage-server
source: services/storage-server
dockerfile: cloud/container/alwatr-services.dockerfile
description: Alwatr Storage Server, Elegant micro in-memory json-like storage nanoservice with disk backed, Fastest NoSQL Database.

# services
- image: comment
source: services/comment
dockerfile: cloud/container/alwatr-services.dockerfile
description: Alwatr Comment API Microservice, Distributed simple and fast comment nanoservice base on @alwatr/storage-server.
description: Alwatr Comment API Nanoservice, Distributed simple and fast comment nanoservice.

- image: flight-crawler
source: services/flight-crawler
dockerfile: cloud/container/alwatr-services.dockerfile
description: Alwatr Flight Crawler Microservic.
description: Alwatr Flight Crawler Nanoservice, Distributed simple and fast flight crawler nanoservice.

- image: form-registering
source: services/form-registering
dockerfile: cloud/container/alwatr-services.dockerfile
description: Alwatr Form Registration API Nanoservice, Distributed simple and fast nanoservice for registering form information.

- image: storage-server
source: services/storage-server
dockerfile: cloud/container/alwatr-services.dockerfile
description: Alwatr Storage Server, Elegant micro in-memory json-like storage nanoservice with disk backed, Fastest NoSQL Database.

- image: telegram-notifier
source: services/telegram-notifier
dockerfile: cloud/container/alwatr-services.dockerfile
description: Alwatr Telegram Notify Microservice.
description: Alwatr Telegram Notify Microservice, Distributed simple and fast telegram notify nanoservice.

# uniquely
- image: flight-finder-api
source: uniquely/flight-finder-api
dockerfile: cloud/container/alwatr-services.dockerfile
description: Alwatr Flight Finder API Microservice.
description: Alwatr Flight Finder Application API.

- image: flight-finder-pwa
source: uniquely/flight-finder-pwa
Expand Down
100 changes: 100 additions & 0 deletions cloud/classic/soffit-form/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
networks:
internal:
alwatr-public-network:
name: alwatr-public-network
external: true

services:
storage-server:
image: ghcr.io/alimd/storage-server:${STORAGE_SERVER_VERSION:-next}

cpu_shares: 1024
mem_limit: 256m

stop_grace_period: 30s

# restart: unless-stopped

networks:
internal:
aliases:
- '${APP_ID}-storage-server'

environment:
- STORAGE_PATH=/storage
- ACCESS_TOKEN=${STORAGE_TOKEN}
- ALWATR_DEBUG=${STORAGE_SERVER_DEBUG:-}

volumes:
- type: bind
source: ./_data/storage
target: /storage
bind:
create_host_path: true

logging:
driver: json-file
options:
max-size: '10m'
max-file: '2'

api:
image: ghcr.io/alimd/form-registering:${API_VERSION:-next}

cpu_shares: 1024
mem_limit: 256m

# restart: unless-stopped

networks:
internal:
alwatr-public-network:

depends_on:
- storage-server

environment:
- STORAGE_HOST=${APP_ID}-storage-server
- STORAGE_PORT=80
- STORAGE_NAME=${STORAGE_NAME}
- STORAGE_TOKEN=${STORAGE_TOKEN}
- ACCESS_TOKEN=${API_TOKEN}
- ALWATR_DEBUG=${API_DEBUG:-}

logging:
driver: json-file
options:
max-size: '10m'
max-file: '2'

labels:
traefik.enable: true
traefik.port: 80
traefik.frontend.rule: Host:${API_DOMAIN}
traefik.frontend.entryPoints: http, https
traefik.frontend.redirect.entryPoint: https

# pwa:
# image: ghcr.io/alimd/form-pwa:${PWA_VERSION:-next}

# cpu_shares: 1024
# mem_limit: 256m

# # restart: unless-stopped

# networks:
# alwatr-public-network:

# logging:
# driver: json-file
# options:
# max-size: '10m'
# max-file: '2'

# labels:
# traefik.enable: true
# traefik.port: 80
# traefik.frontend.rule: Host:${PWA_DOMAIN}
# traefik.frontend.entryPoints: http, https
# traefik.frontend.redirect.entryPoint: https
# # traefik.frontend.auth.basic.users: $PWA_AUTH
3 changes: 3 additions & 0 deletions cloud/classic/soffit-form/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

source ../lib/deploy.sh
13 changes: 13 additions & 0 deletions cloud/classic/soffit-form/env/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
U2FsdGVkX19/x0riPbP6pToYo1yPFh2XRpxZp7QoTzvdAF9EF3V8CUqdXmrd88Or
skaa6xz3bHAoorjKYsNo7rEW3bBxy9ILFdFjTb9j+C0R2EWqAgncmkQr8GEBMqSq
H2lyv94jCSAAJFzQbts2YOHWUxMi92zsnu+F7d9DI1lX6LMHNV1b3zB9PatipQsx
EfRv1vgcOrOzIOcofa25UNVf3hkHQnzk3Lh4XHlfH2wv4LmALZyi0vSKNzoBWW5e
sdcSQNM+E6kiNdFQdiFz+QZThCKx1NjKUSjTLaLUzkjvRC91yl6zLNwVcB6X8vfA
QInHNdMtbPmTbQ/5O0khoNGR7S1gxpL0aNoQyd2gP22uWJlWbGNZl0+ADV6+2HQz
kXvFPBy/TpKTEAJY+nYcEdwNwbSH89hH2PWx0iErX5w+EpKUkDc18xTjPZEB992n
YDhBmDVwQ3NHaFb/GZn2RJqtYmzBaGSi8otLLH8CDGJbg3t4IRTdC6Yo+sgMNJSX
f3WZOPvWwNiujT97Q1Anvf62p7QksWtkSz/rZYdVxwnawZ1aGrGTRSc+Vjxs3Yt9
alfIdhUDsOT5FnlIZtcaIJiYp+qmJnxibLvLKT3t/QRrps0pqqTfkDlIgeEaa+lr
dQ2afr2wOejIQrwf54sDT/755ibVyF7tk+BX1YrFkSpG/7Hz/qHgJuXMGIKHYwkD
o+LThXy0r1TGAQ4gWOUHbAXudMCTFHmc8ByGf5XXhUKDdHwa78WjgM+DUhOs9Lv4
Ex22GFGBseDgklobcUkiZg==
2 changes: 1 addition & 1 deletion services/comment/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Comment API Nanoservice

Distributed simple and fast comment api nanoservice base on [@alwatr/storage-server](../storage-server/).
Distributed simple and fast comment api nanoservice.
2 changes: 1 addition & 1 deletion services/comment/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@alwatr/comment",
"version": "0.27.0",
"description": "Alwatr Comment API Nanoservice, Distributed simple and fast comment nanoservice base on @alwatr/storage-server",
"description": "Alwatr Comment API Nanoservice, Distributed simple and fast comment nanoservice.",
"type": "module",
"keywords": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion services/comment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import './route/patch.js';
import './route/storage.js';
import {logger} from './config.js';

logger.logOther('..:: Alwatr Comment Nanoservice API ::..');
logger.logOther('..:: Alwatr Comment API Nanoservice ::..');
2 changes: 1 addition & 1 deletion services/comment/src/route/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {nanoServer} from '../lib/nano-server.js';
nanoServer.route('GET', '/', () => ({
ok: true,
data: {
app: 'Alwatr Comment API Microservice',
app: '..:: Alwatr Comment API Nanoservice ::..',
message: 'Hello ;)',
},
}));
2 changes: 1 addition & 1 deletion services/flight-crawler/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Flight Crawler Nanoservice

Distributed simple and fast flight crawler nanoservice base on [@alwatr/storage-server](../storage-server/).
Distributed simple and fast flight crawler nanoservice.
2 changes: 1 addition & 1 deletion services/flight-crawler/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@alwatr/flight-finder-crawler",
"version": "0.27.0",
"description": "Alwatr Flight Crawler Nanoservice, Distributed simple and fast flight crawler nanoservice base on",
"description": "Alwatr Flight Crawler Nanoservice, Distributed simple and fast flight crawler nanoservice.",
"type": "module",
"author": "S. Ali Mihandoost <[email protected]> (https://ali.mihandoost.com)",
"private": true,
Expand Down
4 changes: 4 additions & 0 deletions services/flight-crawler/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {logger} from './config.js';
import {crawlAllJobs} from './crawl.js';

logger.logOther('..:: Alwatr Flight Crawler Nanoservice ::..');

crawlAllJobs();

3 changes: 3 additions & 0 deletions services/form-registering/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Form Registration API Nanoservice

Distributed simple and fast nanoservice for registering form information.
50 changes: 50 additions & 0 deletions services/form-registering/demo.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@apiUrl = http://127.0.0.1:8000
@apiVersion = v0
@token = YOUR_SECRET_TOKEN

### home
GET {{apiUrl}}/

### Add new form
PUT {{apiUrl}}/form/
Authorization: Bearer {{token}}
Content-Type: application/json

{
"filed1": "test1",
"filed2": "test2",
"filed13": "test3"
}

### Get storage
GET {{apiUrl}}/form/?storage
Authorization: Bearer {{token}}



### === Test other routes and errors ===

### Page Home
GET {{apiUrl}}/{{apiVersion}}

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

### Page 404 (wrong method)
POST {{apiUrl}}/{{apiVersion}}

### Page health
GET {{apiUrl}}/{{apiVersion}}/health

### empty body
POST {{apiUrl}}/{{apiVersion}}/echo
Content-Type: application/json

### invalid json
POST {{apiUrl}}/{{apiVersion}}/echo
Content-Type: application/json

{
"a": 1,
b: 2,
}
65 changes: 65 additions & 0 deletions services/form-registering/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "@alwatr/form-registration",
"version": "0.27.0",
"description": "Alwatr Form Registration API Nanoservice, Distributed simple and fast nanoservice for registering form information.",
"type": "module",
"keywords": [
"api",
"form",
"microservice",
"nanoservice",
"typescript",
"alwatr"
],
"author": "S. Ali Mihandoost <[email protected]> (https://ali.mihandoost.com)",
"contributors": [
"S. Amir Mohammad Najafi <[email protected]> (https://njfamirm.ir)"
],
"license": "MIT",
"private": true,
"engines": {
"node": ">=19.0.0",
"npm": ">=8.0.0",
"yarn": ">=1.22.0"
},
"repository": {
"type": "git",
"url": "https://github.com/AliMD/alwatr",
"directory": "services/form"
},
"homepage": "https://github.com/AliMD/alwatr/tree/main/services/form#readme",
"bugs": {
"url": "https://github.com/AliMD/alwatr/issues"
},
"scripts": {
"b": "yarn build",
"c": "yarn clean",
"cb": "run-s clean build",
"s": "yarn start",
"w": "yarn watch",
"start": "NODE_OPTIONS=--enable-source-maps run-s clean build serve",
"build": "yarn build:es --analyze=verbose",
"build:ts": "tsc --build",
"build:es": "esbuild src/index.ts --platform=node --target=node19 --bundle --format=esm --minify --sourcemap --outdir=dist --out-extension:.js=.mjs",
"clean": "rimraf dist build .tsbuildinfo **/*.{d.ts,map} src/**/*.{js,cjs,mjs}",
"serve": "node --enable-source-maps dist/index.mjs",
"serve:debug": "node --inspect --enable-source-maps dist/index.mjs",
"watch": "run-s clean build && run-p watch:es watch:node",
"watch:node": "nodemon -w dist/ --enable-source-maps dist/index.mjs",
"watch:debug-node": "nodemon -w dist/ --inspect --enable-source-maps dist/index.mjs",
"watch:ts": "yarn build:ts --watch --preserveWatchOutput",
"watch:es": "yarn build:es --watch"
},
"devDependencies": {
"@alwatr/logger": "^0.27.0",
"@alwatr/nano-server": "^0.27.0",
"@alwatr/type": "^0.27.0",
"@alwatr/storage-client": "^0.27.0",
"@types/node": "^18.11.18",
"esbuild": "^0.16.14",
"nodemon": "^2.0.20",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"typescript": "^4.9.4"
}
}
20 changes: 20 additions & 0 deletions services/form-registering/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {createLogger} from '@alwatr/logger';

export const logger = createLogger('form');

export const config = {
nanoServer: {
host: process.env.HOST ?? '0.0.0.0',
port: process.env.PORT != null ? +process.env.PORT : 8000,
allowAllOrigin: true,
accessToken: process.env.ACCESS_TOKEN ?? 'YOUR_SECRET_TOKEN',
},
storage: {
name: process.env.STORAGE_NAME ?? 'form',
host: process.env.STORAGE_HOST ?? '127.0.0.1',
port: process.env.STORAGE_PORT != null ? +process.env.STORAGE_PORT : 9000,
token: process.env.STORAGE_TOKEN ?? 'YOUR_SECRET_TOKEN',
},
};

logger.logProperty('config', config);
7 changes: 7 additions & 0 deletions services/form-registering/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {logger} from './config.js';

import './route/home.js';
import './route/put.js';
import './route/storage.js';

logger.logOther('..:: Alwatr Form Registration API Nanoservice ::..');
5 changes: 5 additions & 0 deletions services/form-registering/src/lib/nano-server.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 nanoServer = new AlwatrNanoServer(config.nanoServer);
7 changes: 7 additions & 0 deletions services/form-registering/src/lib/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {AlwatrStorageClient} from '@alwatr/storage-client';

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

import type {AlwatrDocumentObject} from '@alwatr/type';

export const storageClient = new AlwatrStorageClient<AlwatrDocumentObject>(config.storage);
9 changes: 9 additions & 0 deletions services/form-registering/src/route/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {nanoServer} from '../lib/nano-server.js';

nanoServer.route('GET', '/', () => ({
ok: true,
data: {
app: '..:: Alwatr Form Registration API Nanoservice ::..',
message: 'Hello ;)',
},
}));
Loading