0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

[Fastify] Add ping endpoint (#2246)

* chore: add ping endpoint

* Update package.json

* rebase from master

* add debug code and logger

* Update index.ts

* Create heavy-ravens-lay.md

* endpoint as plugin

* chore: format

* Update packages/core/server/debug/index.ts

Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>

* add logger instance to fastify

* 4873 port

* format file

* add logger

Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
This commit is contained in:
Juan Picado 2021-05-22 06:56:37 +02:00 committed by GitHub
parent 4ebf18816a
commit 55ee3fdd97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 159 additions and 16 deletions

View file

@ -0,0 +1,6 @@
---
'@verdaccio/cli': minor
'@verdaccio/fastify-migration': minor
---
[Fastify] Add ping endpoint

View file

@ -40,7 +40,8 @@
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
"watch": "pnpm build:js --F --watch",
"build": "pnpm run build:js && pnpm run build:types"
"build": "pnpm run build:js && pnpm run build:types",
"start": "ts-node src/index.ts"
},
"dependencies": {
"@verdaccio/config": "workspace:6.0.0-6-next.6",
@ -53,6 +54,9 @@
"kleur": "3.0.3",
"semver": "7.3.2"
},
"devDependencies": {
"ts-node": "9.1.1"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/verdaccio"

View file

@ -1,6 +1,8 @@
import { Command, Option } from 'clipanion';
import { findConfigFile, parseConfigFile } from '@verdaccio/config';
import { setup, logger } from '@verdaccio/logger';
import server from '@verdaccio/fastify-migration';
import { ConfigRuntime } from '@verdaccio/types';
export const DEFAULT_PROCESS_NAME: string = 'verdaccio';
@ -19,17 +21,29 @@ export class NewServer extends Command {
description: 'use this configuration file (default: ./config.yaml)',
});
private initLogger(logConfig: ConfigRuntime) {
try {
if (logConfig.logs) {
process.emitWarning('config.logs is deprecated, rename configuration to "config.log"');
}
// FUTURE: remove fallback when is ready
setup(logConfig.log || logConfig.logs);
} catch {
throw new Error('error on init logger');
}
}
public async execute() {
try {
const configPathLocation = findConfigFile(this.config as string);
const configParsed = parseConfigFile(configPathLocation);
const { web } = configParsed;
this.initLogger(configParsed);
process.title = web?.title || DEFAULT_PROCESS_NAME;
// const { version, name } = require('../../package.json');
const ser = await server();
await ser.listen(4000);
console.log('fastify running on port 4000');
const ser = await server({ logger });
await ser.listen(4873);
} catch (err) {
console.error(err);
process.exit(1);

View file

@ -0,0 +1,39 @@
storage: ./storage
plugins: ./plugins
web:
title: Verdaccio
auth:
htpasswd:
file: ./htpasswd
uplinks:
npmjs:
url: https://registry.npmjs.org/
packages:
'@*/*':
access: $all
publish: $authenticated
unpublish: $authenticated
proxy: npmjs
'**':
access: $all
publish: $authenticated
unpublish: $authenticated
proxy: npmjs
server:
keepAliveTimeout: 60
middlewares:
audit:
enabled: true
log: { type: stdout, format: pretty, level: http }
flags:
token: false
search: false
i18n:
web: en-US

View file

@ -0,0 +1,30 @@
import path from 'path';
import buildDebug from 'debug';
import { parseConfigFile } from '@verdaccio/config';
import { setup, logger } from '@verdaccio/logger';
import server from '../src/index';
const debug = buildDebug('verdaccio:fastify:debug');
/**
* This file is intended for fast development and debug, it should
* be removed eventually and the app start from @verdaccio/cli package.
*/
(async () => {
try {
const configFile = path.join(__dirname, './fastify-conf.yaml');
debug('configFile %s', configFile);
const configParsed = parseConfigFile(configFile);
setup(configParsed.log);
logger.info(`config location ${configFile}`);
debug('configParsed %s', configParsed);
process.title = 'fastify-verdaccio';
const ser = await server({ logger });
await ser.listen(4873);
logger.info('fastify running on port 4873');
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
process.exit(1);
}
})();

View file

@ -34,10 +34,15 @@
"access": "public"
},
"dependencies": {
"fastify": "3.14.2"
"@verdaccio/logger": "workspace:6.0.0-6-next.4",
"fastify": "3.15.1",
"fastify-plugin": "3.0.0",
"debug": "4.3.1"
},
"devDependencies": {
"@verdaccio/types": "workspace:11.0.0-6-next.7"
"@verdaccio/types": "workspace:11.0.0-6-next.7",
"@verdaccio/config": "workspace:6.0.0-6-next.6",
"ts-node": "9.1.1"
},
"scripts": {
"clean": "rimraf ./build",
@ -45,7 +50,8 @@
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
"watch": "pnpm build:js -- --watch",
"build": "pnpm run build:js && pnpm run build:types"
"build": "pnpm run build:js && pnpm run build:types",
"start": "ts-node debug/index.ts"
},
"funding": {
"type": "opencollective",

View file

@ -0,0 +1,10 @@
import { logger } from '@verdaccio/logger';
async function pingRoute(fastify) {
fastify.get('/-/ping', async () => {
logger.http('ping endpoint');
return {};
});
}
export default pingRoute;

View file

@ -1,12 +1,14 @@
import fastify from 'fastify';
import buildDebug from 'debug';
async function startServer() {
const app = fastify();
import ping from './endpoints/ping';
app.get('/', async (request, reply) => {
return { hello: 'world' };
});
const debug = buildDebug('verdaccio:fastify');
async function startServer({ logger }) {
debug('start server');
const app = fastify({ logger });
app.register(ping);
return app;
}

View file

@ -303,6 +303,7 @@ importers:
envinfo: 7.4.0
kleur: 3.0.3
semver: 7.3.2
ts-node: 9.1.1
dependencies:
'@verdaccio/config': link:../config
'@verdaccio/fastify-migration': link:../core/server
@ -313,6 +314,8 @@ importers:
envinfo: 7.4.0
kleur: 3.0.3
semver: 7.3.2
devDependencies:
ts-node: 9.1.1
packages/config:
specifiers:
@ -419,12 +422,22 @@ importers:
packages/core/server:
specifiers:
'@verdaccio/config': workspace:6.0.0-6-next.6
'@verdaccio/logger': workspace:6.0.0-6-next.4
'@verdaccio/types': workspace:11.0.0-6-next.7
fastify: 3.14.2
debug: 4.3.1
fastify: 3.15.1
fastify-plugin: 3.0.0
ts-node: 9.1.1
dependencies:
fastify: 3.14.2
'@verdaccio/logger': link:../../logger
debug: 4.3.1
fastify: 3.15.1
fastify-plugin: 3.0.0
devDependencies:
'@verdaccio/config': link:../../config
'@verdaccio/types': link:../types
ts-node: 9.1.1
packages/core/streams:
specifiers:
@ -9205,12 +9218,16 @@ packages:
resolution: {integrity: sha512-oCfpcsDndgnDVgiI7bwFKAun2dO+4h84vBlkWsWnz/OUK9Reff5UFoFl241xTiLeHWX/vU9zkDVXqYUxjOwHcQ==}
dev: false
/fastify-plugin/3.0.0:
resolution: {integrity: sha512-ZdCvKEEd92DNLps5n0v231Bha8bkz1DjnPP/aEz37rz/q42Z5JVLmgnqR4DYuNn3NXAO3IDCPyRvgvxtJ4Ym4w==}
dev: false
/fastify-warning/0.2.0:
resolution: {integrity: sha512-s1EQguBw/9qtc1p/WTY4eq9WMRIACkj+HTcOIK1in4MV5aFaQC9ZCIt0dJ7pr5bIf4lPpHvAtP2ywpTNgs7hqw==}
dev: false
/fastify/3.14.2:
resolution: {integrity: sha512-/PY//7gJnGxLQORaRHCEW148vpFKFpBIQNz1Yo/DxbHuk5EQqK2comzyE2ug8FSEldDX8nleapTshl0m78Px2w==}
/fastify/3.15.1:
resolution: {integrity: sha512-QZBGrSOwcR+IJF5OwYTZ5662wEd68SqC6sG4aMu0GncKbYlG9GF88EF2PzN2HfXCCD9K0d/+ZNowuF8S893mOg==}
engines: {node: '>=10.16.0'}
dependencies:
'@fastify/proxy-addr': 3.0.0
@ -17769,6 +17786,21 @@ packages:
resolution: {integrity: sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==}
dev: true
/ts-node/9.1.1:
resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==}
engines: {node: '>=10.0.0'}
hasBin: true
peerDependencies:
typescript: '>=2.7'
dependencies:
arg: 4.1.3
create-require: 1.1.1
diff: 4.0.2
make-error: 1.3.6
source-map-support: 0.5.19
yn: 3.1.1
dev: true
/ts-node/9.1.1_typescript@4.2.4:
resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==}
engines: {node: '>=10.0.0'}