added logger
This commit is contained in:
2
.eslintignore
Normal file
2
.eslintignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
175
.eslintrc.json
Normal file
175
.eslintrc.json
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
{
|
||||||
|
"env":{
|
||||||
|
"es2021":true,
|
||||||
|
"node":true
|
||||||
|
},
|
||||||
|
"extends":[
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:@typescript-eslint/eslint-recommended",
|
||||||
|
"plugin:@typescript-eslint/recommended",
|
||||||
|
"plugin:promise/recommended",
|
||||||
|
"plugin:import/recommended",
|
||||||
|
"plugin:import/typescript"
|
||||||
|
],
|
||||||
|
"parser":"@typescript-eslint/parser",
|
||||||
|
"parserOptions":{
|
||||||
|
"project":"./tsconfig.json",
|
||||||
|
"ecmaVersion":"latest",
|
||||||
|
"sourceType":"module"
|
||||||
|
},
|
||||||
|
"plugins":[
|
||||||
|
"@typescript-eslint",
|
||||||
|
"unused-imports",
|
||||||
|
"promise"
|
||||||
|
],
|
||||||
|
"rules":{
|
||||||
|
"no-console":[
|
||||||
|
"error"
|
||||||
|
],
|
||||||
|
"semi":"off",
|
||||||
|
"@typescript-eslint/semi":[
|
||||||
|
"error",
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"quotes":[
|
||||||
|
"error",
|
||||||
|
"double"
|
||||||
|
],
|
||||||
|
"no-multiple-empty-lines":[
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"max":1,
|
||||||
|
"maxEOF":1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"spaced-comment":[
|
||||||
|
"error",
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"padding-line-between-statements":[
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"blankLine":"always",
|
||||||
|
"prev":"import",
|
||||||
|
"next":"*"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"blankLine":"never",
|
||||||
|
"prev":"import",
|
||||||
|
"next":"import"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"blankLine":"always",
|
||||||
|
"prev":"class",
|
||||||
|
"next":"*"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"lines-between-class-members":"off",
|
||||||
|
"@typescript-eslint/lines-between-class-members":[
|
||||||
|
"error",
|
||||||
|
"always",
|
||||||
|
{
|
||||||
|
"exceptAfterSingleLine":true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@typescript-eslint/await-thenable":"error",
|
||||||
|
"@typescript-eslint/no-for-in-array":"error",
|
||||||
|
"@typescript-eslint/no-misused-promises":"error",
|
||||||
|
"@typescript-eslint/explicit-function-return-type":"error",
|
||||||
|
"@typescript-eslint/no-unnecessary-type-assertion":"error",
|
||||||
|
"@typescript-eslint/prefer-includes":"error",
|
||||||
|
"@typescript-eslint/prefer-regexp-exec":"error",
|
||||||
|
"@typescript-eslint/prefer-string-starts-ends-with":"error",
|
||||||
|
"@typescript-eslint/explicit-member-accessibility":"error",
|
||||||
|
"require-await":"off",
|
||||||
|
"@typescript-eslint/require-await":"error",
|
||||||
|
"@typescript-eslint/unbound-method":"error",
|
||||||
|
"no-var":"error",
|
||||||
|
"prefer-const":"error",
|
||||||
|
"prefer-rest-params":"error",
|
||||||
|
"prefer-spread":"error",
|
||||||
|
"no-use-before-define":"off",
|
||||||
|
"@typescript-eslint/no-use-before-define":"error",
|
||||||
|
"no-useless-constructor":"off",
|
||||||
|
"@typescript-eslint/no-useless-constructor":"error",
|
||||||
|
"@typescript-eslint/no-var-requires":"error",
|
||||||
|
"@typescript-eslint/no-misused-new":"error",
|
||||||
|
"@typescript-eslint/no-non-null-asserted-optional-chain":"error",
|
||||||
|
"@typescript-eslint/no-non-null-assertion":"error",
|
||||||
|
"@typescript-eslint/no-parameter-properties":"error",
|
||||||
|
"@typescript-eslint/no-require-imports":"error",
|
||||||
|
"@typescript-eslint/no-this-alias":"error",
|
||||||
|
"@typescript-eslint/no-throw-literal":"error",
|
||||||
|
"@typescript-eslint/no-type-alias":[
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"allowAliases":"always"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-unsafe-call":"error",
|
||||||
|
"@typescript-eslint/no-unsafe-member-access":"error",
|
||||||
|
"@typescript-eslint/no-unsafe-return":"error",
|
||||||
|
"no-unused-expressions":"off",
|
||||||
|
"@typescript-eslint/no-unused-expressions":"error",
|
||||||
|
"no-extra-semi":"off",
|
||||||
|
"@typescript-eslint/no-extra-semi":"error",
|
||||||
|
"@typescript-eslint/no-extraneous-class":"error",
|
||||||
|
"@typescript-eslint/no-floating-promises":"error",
|
||||||
|
"@typescript-eslint/no-implied-eval":"error",
|
||||||
|
"comma-spacing":"off",
|
||||||
|
"@typescript-eslint/comma-spacing":"error",
|
||||||
|
"func-call-spacing":"off",
|
||||||
|
"@typescript-eslint/func-call-spacing":"error",
|
||||||
|
"space-before-function-paren":"off",
|
||||||
|
"@typescript-eslint/space-before-function-paren":"error",
|
||||||
|
"@typescript-eslint/type-annotation-spacing":"error",
|
||||||
|
"no-magic-numbers":"off",
|
||||||
|
"@typescript-eslint/no-magic-numbers":[
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"ignoreArrayIndexes":true,
|
||||||
|
"ignore":[
|
||||||
|
-1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-unnecessary-boolean-literal-compare":"warn",
|
||||||
|
"@typescript-eslint/no-unnecessary-condition":"warn",
|
||||||
|
"@typescript-eslint/no-unnecessary-qualifier":"warn",
|
||||||
|
"@typescript-eslint/no-unnecessary-type-arguments":"warn",
|
||||||
|
"@typescript-eslint/member-ordering":"warn",
|
||||||
|
"@typescript-eslint/strict-boolean-expressions":"off",
|
||||||
|
"@typescript-eslint/prefer-as-const":"warn",
|
||||||
|
"@typescript-eslint/prefer-for-of":"warn",
|
||||||
|
"@typescript-eslint/prefer-function-type":"warn",
|
||||||
|
"@typescript-eslint/prefer-namespace-keyword":"warn",
|
||||||
|
"@typescript-eslint/prefer-nullish-coalescing":"warn",
|
||||||
|
"@typescript-eslint/prefer-optional-chain":"warn",
|
||||||
|
"@typescript-eslint/prefer-readonly":"warn",
|
||||||
|
"@typescript-eslint/prefer-readonly-parameter-types":"off",
|
||||||
|
"@typescript-eslint/no-explicit-any":1,
|
||||||
|
"@typescript-eslint/no-inferrable-types":[
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
"ignoreParameters":true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"no-unused-vars":"off",
|
||||||
|
"unused-imports/no-unused-imports":"error",
|
||||||
|
"unused-imports/no-unused-vars":[
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
"vars":"all",
|
||||||
|
"varsIgnorePattern":"^_",
|
||||||
|
"args":"after-used",
|
||||||
|
"argsIgnorePattern":"^_"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"indent": "off",
|
||||||
|
"@typescript-eslint/indent": ["error", 2],
|
||||||
|
}
|
||||||
|
}
|
||||||
105
.gitignore
vendored
Normal file
105
.gitignore
vendored
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
config
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
.env.test
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
.next
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
.cache/
|
||||||
|
# Comment in the public line in if your project uses Gatsby and *not* Next.js
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
.tern-port
|
||||||
14
.vscode/extensions.json
vendored
Normal file
14
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"dbaeumer.vscode-eslint",
|
||||||
|
"esbenp.prettier-vscode",
|
||||||
|
"aaron-bond.better-comments",
|
||||||
|
"vscode-icons-team.vscode-icons",
|
||||||
|
"eamodio.gitlens",
|
||||||
|
"christian-kohler.path-intellisense",
|
||||||
|
"eg2.vscode-npm-script",
|
||||||
|
"christian-kohler.npm-intellisense",
|
||||||
|
"esbenp.prettier-vscode",
|
||||||
|
"asciidoctor.asciidoctor-vscode"
|
||||||
|
]
|
||||||
|
}
|
||||||
20
.vscode/launch.json
vendored
Normal file
20
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [{
|
||||||
|
"name": "Node Inspector",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": ["${workspaceRoot}/src/server.ts"],
|
||||||
|
"runtimeArgs": ["--loader", "./src/myloader.mjs", "--experimental-top-level-await", "--experimental-specifier-resolution=node", "--experimental-specifier-resolution=node"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"sourceMaps": true,
|
||||||
|
"trace": "all",
|
||||||
|
"outputCapture": "std",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart",
|
||||||
|
"env": {
|
||||||
|
"TS_NODE_IGNORE": "false",
|
||||||
|
"NODE_ENV": "development"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
25
.vscode/settings.json
vendored
Normal file
25
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.fixAll.eslint": true
|
||||||
|
},
|
||||||
|
"eslint.validate": ["javascript", "typescript"],
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"[javascript]": {
|
||||||
|
"editor.formatOnSave": false
|
||||||
|
},
|
||||||
|
"[typescript]": {
|
||||||
|
"editor.formatOnSave": false
|
||||||
|
},
|
||||||
|
"[markdown]": {
|
||||||
|
"editor.formatOnSave": false
|
||||||
|
},
|
||||||
|
"search.exclude": {
|
||||||
|
"**/node_modules": true,
|
||||||
|
"**/bower_components": true,
|
||||||
|
"**/dist": true,
|
||||||
|
"**/coverage": true
|
||||||
|
},
|
||||||
|
"typescript.referencesCodeLens.enabled": true,
|
||||||
|
"appService.zipIgnorePattern": [".vscode{,/**}"],
|
||||||
|
"appService.deploySubpath": ""
|
||||||
|
}
|
||||||
47
package.json
Normal file
47
package.json
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"name": "anthill-pot",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Anthill Backup Pot",
|
||||||
|
"main": "server.ts",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node --no-warnings --loader ./src/myloader.mjs --experimental-modules --es-module-specifier-resolution=node ./dist/server.js",
|
||||||
|
"dev": "node --no-warnings --loader ./src/myloader.mjs --experimental-modules --es-module-specifier-resolution=node ./src/server.ts",
|
||||||
|
"build": "tsc -p tsconfig.json",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"lint": "eslint --fix --ext ts src/"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.joshua-schnabel.de/joshua_schnabel/anthill-pot.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"Backup",
|
||||||
|
"Sync",
|
||||||
|
"Storage"
|
||||||
|
],
|
||||||
|
"author": "Joshua Schnabel",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@gquittet/graceful-server": "^2.5.2",
|
||||||
|
"fastify": "^3.25.3",
|
||||||
|
"fastify-sensible": "^3.1.2",
|
||||||
|
"winston": "^3.4.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tsconfig/node16": "^1.0.2",
|
||||||
|
"@types/node": "^17.0.9",
|
||||||
|
"@types/triple-beam": "^1.3.2",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
||||||
|
"@typescript-eslint/parser": "^5.10.0",
|
||||||
|
"eslint": "^8.7.0",
|
||||||
|
"eslint-plugin-import": "^2.25.4",
|
||||||
|
"eslint-plugin-promise": "^6.0.0",
|
||||||
|
"eslint-plugin-unused-imports": "^2.0.0",
|
||||||
|
"ts-node": "^10.4.0",
|
||||||
|
"typescript": "^4.5.4"
|
||||||
|
},
|
||||||
|
"_moduleAliases": {
|
||||||
|
"@logger/*": "./dist/logger/*"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
src/abc/xyz.ts
Normal file
5
src/abc/xyz.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class InfrastructureAutoLoadable {
|
||||||
|
public load (): void {console.log("TEST");}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new InfrastructureAutoLoadable();
|
||||||
40
src/framework/logger/logger.ts
Normal file
40
src/framework/logger/logger.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import winston, { format, transports, transport as Transport, Logger } from "winston";
|
||||||
|
import { Format } from "logform";
|
||||||
|
|
||||||
|
const { combine, timestamp, label, printf, errors, splat } = format;
|
||||||
|
|
||||||
|
// Custom logging format
|
||||||
|
const customFormat = printf(({ level, message, label, timestamp, stack }) => {
|
||||||
|
return `${timestamp} [${label || "-"}] ${level}: ${message} ${stack || ""}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Custom combined logging format:
|
||||||
|
const customCombinedFormat = (module: string): Format =>
|
||||||
|
combine(
|
||||||
|
errors({ stack: true }),
|
||||||
|
format.colorize({ level: true }),
|
||||||
|
label({ label: module }),
|
||||||
|
timestamp(),
|
||||||
|
splat(),
|
||||||
|
customFormat
|
||||||
|
);
|
||||||
|
|
||||||
|
// Custom transports:
|
||||||
|
const customTransports = (): Transport[] => [new transports.Console()];
|
||||||
|
|
||||||
|
// Container to provide different pre-configured loggers
|
||||||
|
const logContainer = new winston.Container();
|
||||||
|
|
||||||
|
// Default logger for modules:
|
||||||
|
const getLogger = (module: string): Logger => {
|
||||||
|
if (!logContainer.has(module)) {
|
||||||
|
logContainer.add(module, {
|
||||||
|
format: customCombinedFormat(module),
|
||||||
|
transports: customTransports()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return logContainer.get(module);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getLogger;
|
||||||
|
export const defaultLogger = getLogger("default");
|
||||||
65
src/myloader.mjs
Normal file
65
src/myloader.mjs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import tsconfig from '../tsconfig.json';
|
||||||
|
import * as path from 'path';
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
import { createRequire } from 'module'
|
||||||
|
const require = createRequire(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
|
const baseURL = "file:///" + path.resolve(path.dirname(''), tsconfig.compilerOptions.baseUrl);
|
||||||
|
|
||||||
|
const esm = require('../node_modules/ts-node/dist/esm')
|
||||||
|
|
||||||
|
const hooks = esm.registerAndCreateEsmHooks()
|
||||||
|
|
||||||
|
function doesAliasMatch(path, specifier) {
|
||||||
|
if (path.alias.endsWith("*") && path.replacement.endsWith("*")) {
|
||||||
|
return specifier.startsWith(path.alias.slice(0, -1));
|
||||||
|
} else if (!path.alias.endsWith("*") && !path.replacement.endsWith("*")) {
|
||||||
|
return (path.alias === specifier);
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
function findAlias(specifier) {
|
||||||
|
const paths = tsconfig.compilerOptions.paths;
|
||||||
|
let found = undefined;
|
||||||
|
Object.keys(paths).forEach(function (path) {
|
||||||
|
let temp = { alias: path, replacement: paths[path][0] };
|
||||||
|
if (doesAliasMatch(temp, specifier)) {
|
||||||
|
found = temp;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
function aliasSpecifier(alias, specifier) {
|
||||||
|
if (alias.alias.endsWith("*")) {
|
||||||
|
return specifier.replace(alias.alias.slice(0, -1), alias.replacement.slice(0, -1));
|
||||||
|
} else {
|
||||||
|
return specifier.replace(alias.alias, alias.replacement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function load(url, context, defaultLoad) {
|
||||||
|
return hooks.load(url, context, defaultLoad)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolve(specifier, context, defaultResolve) {
|
||||||
|
const { parentURL = baseURL + "/server.ts" } = context;
|
||||||
|
const alias = findAlias(specifier);
|
||||||
|
if (alias !== undefined) {
|
||||||
|
const tspecifier = specifier;
|
||||||
|
specifier = aliasSpecifier(alias, specifier);
|
||||||
|
let relativpath = path.relative(path.dirname(parentURL), baseURL);
|
||||||
|
if (relativpath === "") relativpath = ".";
|
||||||
|
specifier = "./" + relativpath + "/" + specifier.replace("./", "");
|
||||||
|
}
|
||||||
|
return hooks.resolve(specifier, context, defaultResolve)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFormat(url, context, defaultGetFormat) {
|
||||||
|
return hooks.getFormat(url, context, defaultGetFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transformSource(source, context, defaultTransformSource) {
|
||||||
|
return hooks.transformSource(source, context, defaultTransformSource);
|
||||||
|
}
|
||||||
63
src/server.ts
Normal file
63
src/server.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import Fastify from "fastify";
|
||||||
|
import fastifySensible from "fastify-sensible";
|
||||||
|
import GracefulServer from "@gquittet/graceful-server";
|
||||||
|
import getlogger, {defaultLogger} from "@logger";
|
||||||
|
|
||||||
|
const fastify = Fastify({
|
||||||
|
logger: true
|
||||||
|
});
|
||||||
|
fastify.register(fastifySensible);
|
||||||
|
|
||||||
|
const gracefulServer = GracefulServer(fastify.server);
|
||||||
|
|
||||||
|
gracefulServer.on(GracefulServer.READY, () => {
|
||||||
|
console.log("Server is ready");
|
||||||
|
});
|
||||||
|
|
||||||
|
gracefulServer.on(GracefulServer.SHUTTING_DOWN, () => {
|
||||||
|
console.log("Server is shutting down");
|
||||||
|
});
|
||||||
|
|
||||||
|
gracefulServer.on(GracefulServer.SHUTDOWN, error => {
|
||||||
|
console.log("Server is down because of", error.message);
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Declare a route
|
||||||
|
fastify.get("/", function (request, reply) {
|
||||||
|
reply.send({ hello: "world" });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Run the server!
|
||||||
|
const start = async () => {
|
||||||
|
try {
|
||||||
|
await fastify.listen(3000);
|
||||||
|
gracefulServer.setReady();
|
||||||
|
} catch (err) {
|
||||||
|
fastify.log.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
start();
|
||||||
|
|
||||||
|
const c = function (): void {
|
||||||
|
const v = function (): void {
|
||||||
|
throw new Error("Oh no!");
|
||||||
|
};
|
||||||
|
return v();
|
||||||
|
};
|
||||||
|
|
||||||
|
const abc = getlogger("abc");
|
||||||
|
abc.info("Ich bin ein Test!");
|
||||||
|
abc.warn("Ich bin ein Test!");
|
||||||
|
try {
|
||||||
|
c();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
abc.warn(e);
|
||||||
|
}
|
||||||
|
const xyz = getlogger("xyz");
|
||||||
|
xyz.error("Ich bin ein Test!");
|
||||||
|
xyz.error("Ich bin ein '%s' Test!", "test");
|
||||||
|
|
||||||
|
defaultLogger.error("Ich bin ein Test!");
|
||||||
18
tsconfig.json
Normal file
18
tsconfig.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"extends": "@tsconfig/node16/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"typeRoots": ["./node_modules/@types"],
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"outDir": "./dist/",
|
||||||
|
"baseUrl": "./src/",
|
||||||
|
"paths": {
|
||||||
|
"@abc/*": ["abc/*"],
|
||||||
|
"@logger": ["framework/logger/logger"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts"],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user