-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #459 from AliMD/feat/commenting-service
feat(service/commenting): new microservice
- Loading branch information
Showing
31 changed files
with
458 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
"MohammadMahdi Zamanian <[email protected]>" | ||
], | ||
"dependencies": { | ||
"@alwatr/logger": "^0.24.1", | ||
"@alwatr/logger": "~0.24.1", | ||
"tslib": "~2.4.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* | ||
!src/ | ||
!package.json | ||
!tsconfig.json | ||
!*.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
ARG NODE_VERSION=19 | ||
FROM docker.io/library/node:${NODE_VERSION}-alpine as builder | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json *.lock ./ | ||
RUN if [ -f *.lock ]; then \ | ||
yarn install --frozen-lockfile --non-interactive; \ | ||
else \ | ||
yarn install --non-interactive; \ | ||
fi; | ||
|
||
COPY . . | ||
RUN yarn build && \ | ||
rm -rf node_modules && \ | ||
yarn install --frozen-lockfile --non-interactive --production && \ | ||
ls -lahF && \ | ||
ls -lAh dist | ||
|
||
# --- | ||
|
||
FROM docker.io/library/node:${NODE_VERSION}-alpine as app | ||
|
||
WORKDIR /app | ||
|
||
RUN apk add --no-cache tini | ||
ENTRYPOINT ["/sbin/tini", "--"] | ||
CMD ["node", "index.js"] | ||
|
||
ENV NODE_ENV production | ||
ENV ALWATR_DEBUG * | ||
ENV HOST 0.0.0.0 | ||
ENV PORT 80 | ||
EXPOSE 80 | ||
|
||
COPY --from=builder /app/node_modules/ ./node_modules/ | ||
COPY --from=builder /app/dist/ ./ | ||
RUN ls -lahF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Comment Service | ||
|
||
Distributed simple and fast comment nanoservice base on [@alwatr/storage-server](../storage-server/). | ||
|
||
## How to use | ||
|
||
Check [demo.http](demo.http). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@apiUrl = http://127.0.0.1:8000 | ||
@apiVersion = v0 | ||
@token = YOUR_SECRET_TOKEN | ||
|
||
### home | ||
GET {{apiUrl}}/ | ||
|
||
### Add new comment | ||
PATCH {{apiUrl}}/?storage=product/test | ||
Authorization: Bearer {{token}} | ||
Content-Type: application/json | ||
|
||
{ | ||
"id": "auto_increment", | ||
"user": "njfamirm", | ||
"type": "text", | ||
"text": "سلام ;)" | ||
} | ||
|
||
### Add new reply | ||
PATCH {{apiUrl}}/?storage=product/test | ||
Authorization: Bearer {{token}} | ||
Content-Type: application/json | ||
|
||
{ | ||
"id": "auto_increment", | ||
"user": "alimd", | ||
"type": "text", | ||
"text": "علیک سلام :)", | ||
"replyId": "1" | ||
} | ||
|
||
### Get all comment | ||
GET {{apiUrl}}/all?storage=product/test | ||
Authorization: Bearer {{token}} | ||
Content-Type: application/json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"name": "@alwatr/comment", | ||
"version": "0.24.1", | ||
"description": "Alwatr Comment API Microservice, Distributed simple and fast comment nanoservice base on @alwatr/storage-server", | ||
"type": "module", | ||
"keywords": [ | ||
"api", | ||
"comment", | ||
"chat", | ||
"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": "packages/service/comment" | ||
}, | ||
"homepage": "https://github.com/AliMD/alwatr/tree/main/packages/service/comment#readme", | ||
"bugs": { | ||
"url": "https://github.com/AliMD/alwatr/issues" | ||
}, | ||
"scripts": { | ||
"l": "yarn lint", | ||
"b": "yarn build", | ||
"cb": "run-s clean build", | ||
"s": "run-s clean build serve", | ||
"w": "yarn watch", | ||
"f": "yarn format", | ||
"fl": "yarn format:eslint", | ||
"fp": "yarn format:prettier", | ||
"start": "yarn serve", | ||
"lint": "run-s lint:*", | ||
"lint:ts": "eslint . --config .eslintrc.json --ext .ts", | ||
"build": "run-s build:*", | ||
"build:ts": "tsc --build", | ||
"format": "run-s format:prettier format:eslint", | ||
"format:eslint": "yarn lint:ts --fix", | ||
"format:prettier": "prettier \"**/*.{html,json,md,ts}\" --write", | ||
"clean": "rimraf dist/", | ||
"serve": "node dist/index.js", | ||
"serve:debug": "node --inspect dist/index.js", | ||
"watch": "run-s clean build && run-p watch:ts watch:node", | ||
"watch:node": "nodemon -w dist/ dist/index.js", | ||
"watch:debug-node": "nodemon -w dist/ --inspect dist/index.js", | ||
"watch:ts": "yarn build:ts --watch --preserveWatchOutput" | ||
}, | ||
"dependencies": { | ||
"@alwatr/logger": "~0.24.1", | ||
"@alwatr/nano-server": "~0.24.1", | ||
"@alwatr/storage-client": "~0.24.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "~18.11.10", | ||
"@typescript-eslint/eslint-plugin": "~5.45.0", | ||
"@typescript-eslint/parser": "~5.45.0", | ||
"eslint": "~8.28.0", | ||
"eslint-config-google": "~0.14.0", | ||
"eslint-import-resolver-typescript": "~3.5.2", | ||
"eslint-plugin-import": "~2.26.0", | ||
"nodemon": "~2.0.20", | ||
"npm-run-all": "~4.1.5", | ||
"prettier": "~2.8.0", | ||
"rimraf": "~3.0.2", | ||
"typescript": "~4.9.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import './route/home.js'; | ||
import './route/patch.js'; | ||
import './route/all.js'; | ||
import {logger} from './lib/config.js'; | ||
|
||
logger.logOther('..:: Alwatr Comment Nanoservice API ::..'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {createLogger} from '@alwatr/logger'; | ||
|
||
export const logger = createLogger('comment'); | ||
|
||
export const config = { | ||
nanoServer: { | ||
host: process.env.HOST ?? '0.0.0.0', | ||
port: process.env.PORT != null ? +process.env.PORT : 8000, | ||
allowAllOrigin: true, | ||
token: process.env.TOKEN ?? 'YOUR_SECRET_TOKEN', | ||
}, | ||
storage: { | ||
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, token: '***'}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {AlwatrStorageClient} from '@alwatr/storage-client'; | ||
|
||
import {config} from './config.js'; | ||
import {Message} from './type.js'; | ||
|
||
export const storage = new AlwatrStorageClient<Message>(config.storage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {AlwatrDocumentObject} from '@alwatr/storage-client'; | ||
|
||
type CommonMessage = AlwatrDocumentObject & { | ||
user: unknown; | ||
replyId?: string; | ||
}; | ||
|
||
export type TextMessage = CommonMessage & { | ||
type: 'text'; | ||
text: string; | ||
}; | ||
|
||
export type PhotoMessage = CommonMessage & { | ||
type: 'photo'; | ||
photo: Record<string, unknown>; | ||
}; | ||
|
||
export type Message = TextMessage | PhotoMessage; |
Oops, something went wrong.