xlox node backend api's
- Testing database using a technique
- Mocking a db with jest
- Dependecy Injection
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM mcr.microsoft.com/devcontainers/javascript-node:0-18 | ||
|
||
# Install MongoDB command line tools - though mongo-database-tools not available on arm64 | ||
ARG MONGO_TOOLS_VERSION=6.0 | ||
RUN . /etc/os-release \ | ||
&& curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \ | ||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \ | ||
&& apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
&& apt-get install -y mongodb-mongosh \ | ||
&& if [ "$(dpkg --print-architecture)" = "amd64" ]; then apt-get install -y mongodb-database-tools; fi \ | ||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* | ||
|
||
# [Optional] Uncomment this section to install additional OS packages. | ||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
# && apt-get -y install --no-install-recommends <your-package-list-here> | ||
|
||
# [Optional] Uncomment if you want to install an additional version of node using nvm | ||
# ARG EXTRA_NODE_VERSION=10 | ||
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" | ||
|
||
# [Optional] Uncomment if you want to install more global node modules | ||
# RUN su node -c "npm install -g <your-package-list-here>" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node-mongo | ||
{ | ||
"name": "Node.js & Mongo DB", | ||
"dockerComposeFile": "docker-compose.yml", | ||
"service": "app", | ||
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
|
||
// Configure tool-specific properties. | ||
"customizations": { | ||
// Configure properties specific to VS Code. | ||
"vscode": { | ||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": ["mongodb.mongodb-vscode"] | ||
} | ||
}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
"forwardPorts": [3000] | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "yarn install", | ||
|
||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "root" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
version: '3.8' | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
volumes: | ||
- ../..:/workspaces:cached | ||
|
||
# Overrides default command so things don't shut down after the process ends. | ||
command: sleep infinity | ||
|
||
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. | ||
network_mode: service:db | ||
|
||
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally. | ||
# (Adding the "ports" property to this file will not forward from a Codespace.) | ||
|
||
db: | ||
image: mongo:latest | ||
restart: unless-stopped | ||
volumes: | ||
- mongodb-data:/data/db | ||
|
||
# Uncomment to change startup options | ||
# environment: | ||
# MONGO_INITDB_ROOT_USERNAME: root | ||
# MONGO_INITDB_ROOT_PASSWORD: example | ||
# MONGO_INITDB_DATABASE: your-database-here | ||
|
||
# Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally. | ||
# (Adding the "ports" property to this file will not forward from a Codespace.) | ||
|
||
volumes: | ||
mongodb-data: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/node_modules | ||
Dockerfile | ||
.dockerignore | ||
.github | ||
ecosystem.config.js | ||
LICENSE | ||
|
||
# Markdown files | ||
CHANGELOG.md | ||
README.md | ||
CONTRIBUTING.md | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DB_NAME=blog | ||
MONGODB_URI=mongodb://127.0.0.1:27017/ | ||
PORT=4000 | ||
NODE_ENV=local |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"rules": { | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"@typescript-eslint/no-explicit-any": "off" | ||
// "quotes": [2, "double", { "avoidEscape": true }] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Code owners file. | ||
# This file controls who is tagged for review for any given pull request. | ||
|
||
# For anything not explicitly taken by someone else: | ||
* @open-telemetry/demo-approvers |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Bug Report | ||
about: Create a report to help us improve | ||
labels: bug | ||
--- | ||
|
||
# Bug Report | ||
|
||
Which version of the demo you are using? (please provide either a specific | ||
[commit | ||
hash](https://github.com/open-telemetry/opentelemetry-demo/commits/main) | ||
or a specific | ||
[release](https://github.com/open-telemetry/opentelemetry-demo/releases)). | ||
|
||
## Symptom | ||
|
||
A clear and concise description of what the bug is. | ||
|
||
**What is the expected behavior?** | ||
|
||
What do you expect to see? | ||
|
||
**What is the actual behavior?** | ||
|
||
What did you see instead? | ||
|
||
## Reproduce | ||
|
||
Provide the minimum required steps to result in the issue you're observing. | ||
|
||
We will close this issue if: | ||
|
||
- The steps you provided are complex. | ||
- If we can not reproduce the behavior you're reporting. | ||
|
||
## Additional Context | ||
|
||
Add any other context about the problem here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: Feature Request | ||
about: Suggest an idea for this project | ||
labels: enhancement | ||
--- | ||
|
||
# Feature Request | ||
|
||
Before opening a feature request against this repo, consider whether the feature | ||
should/could be implemented in the [other OpenTelemetry client | ||
libraries](https://github.com/open-telemetry/). If so, please [open an issue on | ||
opentelemetry-specification](https://github.com/open-telemetry/opentelemetry-specification/issues/new) | ||
first. | ||
|
||
**Is your feature request related to a problem?** | ||
|
||
If so, provide a concise description of the problem. | ||
|
||
**Describe the solution you'd like:** | ||
|
||
What do you want to happen instead? What is the expected behavior? | ||
|
||
**Describe alternatives you've considered.** | ||
|
||
Which alternative solutions or features have you considered? | ||
|
||
## Additional Context | ||
|
||
Add any other context about the feature request here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
name: Question | ||
about: Create a question to help us improve our knowledge base and documentation | ||
labels: question | ||
--- | ||
|
||
# Question | ||
|
||
Use [Github Discussions](https://github.com/open-telemetry/opentelemetry-demo/discussions/). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!-- | ||
We appreciate your contribution to the OpenTelemetry project! 👋🎉 | ||
Before creating a pull request, please make sure: | ||
- Your PR is solving one problem | ||
- Please provide enough information so that others can review your pull request | ||
- You have read the guide for contributing | ||
- See https://github.com/open-telemetry/opentelemetry-js/blob/main/CONTRIBUTING.md | ||
- You signed all your commits (otherwise we won't be able to merge the PR) | ||
- See https://github.com/open-telemetry/community/blob/master/CONTRIBUTING.md#sign-the-cla | ||
- You added unit tests for the new functionality | ||
- You mention in the PR description which issue it is addressing, e.g. "Fixes #xxx". This will auto-close | ||
the issue that your PR fixes (if such) | ||
--> | ||
|
||
## Which problem is this PR solving? | ||
|
||
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. | ||
|
||
Fixes # (issue) | ||
|
||
## Short description of the changes | ||
|
||
## Type of change | ||
|
||
Please delete options that are not relevant. | ||
|
||
- [ ] Bug fix (non-breaking change which fixes an issue) | ||
- [ ] New feature (non-breaking change which adds functionality) | ||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) | ||
- [ ] This change requires a documentation update | ||
|
||
## How Has This Been Tested? | ||
|
||
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration | ||
|
||
- [ ] Test A | ||
|
||
## Checklist: | ||
|
||
- [ ] Followed the style guidelines of this project | ||
- [ ] Unit tests have been added | ||
- [ ] Documentation has been updated |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright The CSH Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
labels: | ||
- "infra" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name-template: "v${{ tag_name }}" | ||
tag-template: "v${{ tag_name }}" | ||
categories: | ||
- title: "Bug Fixes" | ||
label: "bug" | ||
types: | ||
- fix | ||
- title: "New Features" | ||
label: "feature" | ||
types: | ||
- feat |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/ | ||
.npmrc | ||
dist/ | ||
client/ | ||
libs/ | ||
*/test/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": ["spectral:oas", "spectral:asyncapi"], | ||
"rules": { | ||
"operation-tags-alphabetical": false | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["spectral:oas", "spectral:asyncapi"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src/shared/environments/\.env\.dev | ||
src/shared/environments/\.env\.local |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Rakshith | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Publish to docker hub | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
|
||
# env: | ||
# IMAGE_TAG: $(node -p -e "require('./package.json').version")" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Login Dockerhub | ||
env: | ||
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}} | ||
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} | ||
run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | ||
|
||
|
||
- name: Set app version from package.json | ||
run: echo "APP_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV | ||
|
||
- name: Build the Docker image | ||
run: docker build -t snrakshith/csh-svc-node:$APP_VERSION . | ||
|
||
- name: Push to Dockerhub | ||
run: docker push snrakshith/csh-svc-node:$APP_VERSION |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import express, { Request, Response } from "express"; | ||
import cors from "cors"; | ||
import swaggerUI from "swagger-ui-express"; | ||
import swaggerJsDoc from "swagger-jsdoc"; | ||
import { swaggerOptions } from "./swaggerOptions"; | ||
import { corsOptions } from "./corsOptions"; | ||
|
||
const port = 4000; | ||
const app = express(); | ||
const specs = swaggerJsDoc(swaggerOptions); | ||
|
||
app.get("/api/docs/healthcheck", (req: Request, res: Response) => { | ||
res.json({ status: 200, message: "Fine!!" }); | ||
}); | ||
|
||
app.get("/api/docs/test", (req: Request, res: Response) => { | ||
res.json({ status: 200, message: "Running Successfully" }); | ||
}); | ||
|
||
app.get("/api/docs/kargo", (req: Request, res: Response) => { | ||
res.json({ status: 200, message: "Ran" }); | ||
}); | ||
|
||
app.use(express.json()); | ||
|
||
app.use(cors(corsOptions)); | ||
|
||
app.use((req, res, next) => { | ||
res.header( | ||
"Access-Control-Allow-Methods", | ||
"PUT, POST, GET, DELETE, PATCH, OPTIONS" | ||
); | ||
next(); | ||
}); | ||
|
||
app.use("/api/docs", swaggerUI.serve, swaggerUI.setup(specs)); | ||
|
||
// OpenAPI Json | ||
app.get("/api-docs.json", (req, res) => { | ||
res.setHeader("Content-Type", "application/json"); | ||
res.send(specs); | ||
}); | ||
|
||
app.listen(port, () => console.log(`listening on ${port}`)); |