Skip to content

Commit

Permalink
feat: replace moragn with http-pino (#101)
Browse files Browse the repository at this point in the history
* chore: update dep js libs

* feat: replace morgan with http-pino

* chore: updated dev container

* chore: add dev cnotainer updates
  • Loading branch information
saidsef authored May 14, 2024
1 parent 0222a69 commit 71fd89e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 72 deletions.
17 changes: 0 additions & 17 deletions .devcontainer/Dockerfile

This file was deleted.

84 changes: 45 additions & 39 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.234.0/containers/javascript-node
// 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
{
"name": "Dev",
"build": {
"dockerfile": "Dockerfile",
"args": { "VARIANT": "20" }
},
"settings": {
"editor.autoIndent": "advanced",
"eslint.lintTask.enable": true,
"git.alwaysSignOff": true,
"git.autofetch": true,
"git.autofetchPeriod": 180,
"git.autorefresh": true,
"git.decorations.enabled": true,
"git.showUnpublishedCommitsButton": "always",
"githubPullRequests.defaultDeletionMethod.selectRemote": true,
"redhat.telemetry.enabled": false,
"telemetry.enableTelemetry": false,
"vscode-kubernetes.kubectl-path.linux": "/usr/local/bin/kubectl",
"vscode-kubernetes.helm-path.linux": "/usr/local/bin/helm",
"tslint.jsEnable": true
"name": "Node.js",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bullseye",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
"customizations": {
"vscode": {
"settings": {
"editor.autoIndent": "advanced",
"eslint.lintTask.enable": true,
"git.alwaysSignOff": true,
"git.autofetch": true,
"git.autofetchPeriod": 180,
"git.autorefresh": true,
"git.decorations.enabled": true,
"git.showUnpublishedCommitsButton": "always",
"githubPullRequests.defaultDeletionMethod.selectRemote": true,
"redhat.telemetry.enabled": false,
"telemetry.enableTelemetry": false,
"tslint.jsEnable": true
},
"extensions": [
"dbaeumer.vscode-eslint",
"GitHub.vscode-pull-request-github",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-vscode-remote.remote-containers",
"ms-vscode.vscode-typescript-tslint-plugin",
"redhat.vscode-yaml"
]
}
},
"extensions": [
"dbaeumer.vscode-eslint",
"GitHub.vscode-pull-request-github",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-vscode-remote.remote-containers",
"ms-vscode.vscode-typescript-tslint-plugin",
"redhat.vscode-yaml"
],
"forwardPorts": [],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [8080],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "cd app && yarn install --prod",
"remoteUser": "node",
"features": {
"kubectl-helm-minikube": {
"version": "1.27",
"minikube": "none"
}
}

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "node"
}
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
26 changes: 12 additions & 14 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
'use strict';

const express = require('express');
const logging = require("morgan");
const logging = require('pino-http');
const compression = require('compression');
const helmet = require('helmet');
const crypto = require('crypto');
const cors = require('cors');

const app = express();
const http = require('http').createServer(app);
const PORT = process.env.PORT || 8080;

app.disable('x-powered-by');
app.enable('trust proxy');
app.use(express.urlencoded({extended: true}));
app.use(express.json()); // support json encoded bodies
app.use(logging("combined"));
app.use(logging({ level: process.env.LOG_LEVEL || 'info' }));
app.use(helmet({
contentSecurityPolicy: {
directives: {
baseUri: ["'self'"],
defaultSrc: ["'self'"],
formAction: ["'none'"],
frameAncestors: ["'none'"],
imgSrc: ["'self"],
imgSrc: ["'self'"],
objectSrc: ["'self'"],
sandbox: ['allow-forms', 'allow-scripts'],
scriptSrc: ["'none'"],
Expand All @@ -33,9 +33,7 @@ app.use(helmet({
referrerPolicy: {policy: 'same-origin'},
}));

app.use(cors());
app.use(compression());
app.disable('x-powered-by');

app.get('/healthz', (req, res, next) => {
res.set({'X-Robots-Tag' : 'noindex, nofollow, noarchive'});
Expand All @@ -48,14 +46,14 @@ app.get("*", (req, res, next) => {
const number = crypto.randomInt(10000);
const sha1 = crypto.createHash('sha1').update(crypto.randomBytes(20)).digest('hex');
res.json({
"message": "Hello World!",
"ip": ip,
"ips": ips,
"random_number": number,
"random_sha1": sha1,
"build": buildID,
"request": headers,
"environment_vars": process.env
message: "Hello World!",
ip: ip,
ips: ips,
random_number: number,
random_sha1: sha1,
build: buildID,
request: headers,
environment_vars: process.env
});
});

Expand Down
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"dependencies": {
"compression": "^1.7.4",
"cors": "^2.8.5",
"express": "^4.18.2",
"express": "^4.19.2",
"helmet": "^7.1.0",
"morgan": "^1.10.0"
"pino-http": "^10.1.0"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 71fd89e

Please sign in to comment.