1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-24 21:15:51 +01:00

chore: env variable for launch fastify (#3295)

* chore: relocate package server

* chore: relocate server packages

* Update ci.yml

* rename packages

* rename package

* chore: refactor fastify endpoints

* chore: fix types requests

* fix warnings

* chore: refactor endpoints

* refactor launch fastify

* Update package.json

* chore: update deps

* Create green-yaks-divide.md
This commit is contained in:
Juan Picado 2022-08-08 07:14:23 +02:00 committed by GitHub
parent 8db9cf93ce
commit 00d1d2a179
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
120 changed files with 523 additions and 601 deletions

@ -1,6 +1,6 @@
---
'@verdaccio/api': major
'@verdaccio/fastify-migration': major
'@verdaccio/server-fastify': major
'@verdaccio/tarball': major
'@verdaccio/local-storage': major
'verdaccio-memory': major

@ -6,7 +6,7 @@
'@verdaccio/commons-api': major
'@verdaccio/core': major
'@verdaccio/local-storage': major
'@verdaccio/fastify-migration': major
'@verdaccio/server-fastify': major
'@verdaccio/streams': major
'@verdaccio/types': major
'@verdaccio/hooks': major

@ -7,7 +7,7 @@
'@verdaccio/file-locking': major
'verdaccio-htpasswd': major
'@verdaccio/readme': major
'@verdaccio/fastify-migration': major
'@verdaccio/server-fastify': major
'@verdaccio/streams': major
'@verdaccio/tarball': major
'@verdaccio/types': major

@ -1,6 +1,6 @@
---
'@verdaccio/api': minor
'@verdaccio/fastify-migration': minor
'@verdaccio/server-fastify': minor
'@verdaccio/hooks': minor
'@verdaccio/logger-prettify': minor
'@verdaccio/proxy': minor

@ -0,0 +1,29 @@
---
'@verdaccio/api': minor
'@verdaccio/cli': minor
'@verdaccio/core': minor
'@verdaccio/node-api': minor
'@verdaccio/server': minor
'@verdaccio/server-fastify': minor
'verdaccio': minor
---
chore: env variable for launch fastify
- Update fastify to major release `v4.3.0`
- Update CLI launcher
via CLI
```
VERDACCIO_SERVER=fastify verdaccio
```
with docker
```
docker run -it --rm --name verdaccio \
-e "VERDACCIO_SERVER=8080" -p 8080:8080 \
-e "VERDACCIO_SERVER=fastify" \
verdaccio/verdaccio
```

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

@ -6,7 +6,7 @@
'@verdaccio/core': minor
'verdaccio-htpasswd': minor
'@verdaccio/local-storage': minor
'@verdaccio/fastify-migration': minor
'@verdaccio/server-fastify': minor
'@verdaccio/tarball': minor
'@verdaccio/types': minor
'@verdaccio/url': minor

@ -35,7 +35,7 @@
"@verdaccio/cli-standalone": "6.0.0-alpha.3",
"@verdaccio/tarball": "11.0.0-alpha.3",
"@verdaccio/url": "11.0.0-alpha.3",
"@verdaccio/fastify-migration": "6.0.0-6-next.9",
"@verdaccio/server-fastify": "6.0.0-6-next.9",
"@verdaccio/eslint-config": "1.0.0",
"@verdaccio/benchmark": "1.0.0",
"@verdaccio/core": "6.0.0-next.0",

@ -1,7 +1,7 @@
---
'verdaccio-htpasswd': patch
'@verdaccio/local-storage': patch
'@verdaccio/fastify-migration': patch
'@verdaccio/server-fastify': patch
'@verdaccio/hooks': patch
'@verdaccio/mock': patch
'@verdaccio/node-api': patch

@ -1,5 +1,5 @@
---
'@verdaccio/fastify-migration': minor
'@verdaccio/server-fastify': minor
'@verdaccio/store': minor
'@verdaccio/utils': minor
'@verdaccio/web': minor

@ -1,6 +1,6 @@
---
'@verdaccio/auth': minor
'@verdaccio/fastify-migration': minor
'@verdaccio/server-fastify': minor
'@verdaccio/web': minor
---

@ -2,9 +2,6 @@ name: CI
on:
push:
branches:
- master
- 'changeset-release/master'
pull_request:
paths:
- .changeset/**

@ -133,7 +133,7 @@
"_debug:reload": "nodemon -d 3 packages/verdaccio/debug/bootstrap.js",
"start:ts": "ts-node packages/verdaccio/src/start.ts -- --listen 8000",
"debug": "node --trace-warnings --trace-uncaught --inspect packages/verdaccio/debug/bootstrap.js",
"debug:fastify": "node --trace-warnings --trace-uncaught --inspect packages/verdaccio/debug/bootstrap.js -- fastify-server",
"debug:fastify": "cross-env VERDACCIO_SERVER=fastify node --trace-warnings --trace-uncaught --inspect packages/verdaccio/debug/bootstrap.js",
"debug:break": "node --trace-warnings --trace-uncaught --inspect-brk packages/verdaccio/debug/bootstrap.js",
"changeset": "changeset",
"changeset:check": "changeset status --since-master",

@ -48,42 +48,6 @@ export default function (route: Router, auth: IAuth, storage: Storage): void {
}
);
route.get(
'/:scopedPackage/-/:scope/:filename',
can('access'),
async function (req: $RequestExtend, res: $ResponseExtend, next): Promise<void> {
const { pkg, filename } = req.params;
const abort = new AbortController();
try {
const stream = (await storage.getTarballNext(pkg, filename, {
signal: abort.signal,
// enableRemote: true,
})) as any;
stream.on('content-length', (size) => {
res.header(HEADER_TYPE.CONTENT_LENGTH, size);
});
stream.once('error', (err) => {
res.locals.report_error(err);
next(err);
});
req.on('abort', () => {
debug('request aborted for %o', req.url);
abort.abort();
});
res.header(HEADERS.CONTENT_TYPE, HEADERS.OCTET_STREAM);
stream.pipe(res);
} catch (err: any) {
// console.log('catch API error request', err);
res.locals.report_error(err);
next(err);
}
}
);
route.get(
'/:pkg/-/:filename',
can('access'),

@ -29,7 +29,7 @@
"path": "../middleware"
},
{
"path": "../server"
"path": "../server/express"
},
{
"path": "../store"

@ -13,7 +13,7 @@
- Updated dependencies [d43894e8]
- Updated dependencies [d08fe29d]
- @verdaccio/config@6.0.0-6-next.14
- @verdaccio/fastify-migration@6.0.0-6-next.23
- @verdaccio/server-fastify@6.0.0-6-next.23
- @verdaccio/node-api@6.0.0-6-next.31
- @verdaccio/core@6.0.0-6-next.5
- @verdaccio/logger@6.0.0-6-next.11
@ -59,20 +59,20 @@
- @verdaccio/core@6.0.0-6-next.5
- @verdaccio/logger@6.0.0-6-next.11
- @verdaccio/node-api@6.0.0-6-next.30
- @verdaccio/fastify-migration@6.0.0-6-next.22
- @verdaccio/server-fastify@6.0.0-6-next.22
## 6.0.0-6-next.30
### Patch Changes
- @verdaccio/fastify-migration@6.0.0-6-next.21
- @verdaccio/server-fastify@6.0.0-6-next.21
- @verdaccio/node-api@6.0.0-6-next.29
## 6.0.0-6-next.29
### Patch Changes
- @verdaccio/fastify-migration@6.0.0-6-next.20
- @verdaccio/server-fastify@6.0.0-6-next.20
- @verdaccio/node-api@6.0.0-6-next.28
## 6.0.0-6-next.28
@ -81,7 +81,7 @@
- Updated dependencies [b78f3525]
- @verdaccio/logger@6.0.0-6-next.10
- @verdaccio/fastify-migration@6.0.0-6-next.19
- @verdaccio/server-fastify@6.0.0-6-next.19
- @verdaccio/node-api@6.0.0-6-next.27
## 6.0.0-6-next.27
@ -91,7 +91,7 @@
- Updated dependencies [730b5d8c]
- @verdaccio/logger@6.0.0-6-next.9
- @verdaccio/node-api@6.0.0-6-next.26
- @verdaccio/fastify-migration@6.0.0-6-next.18
- @verdaccio/server-fastify@6.0.0-6-next.18
## 6.0.0-6-next.26
@ -100,7 +100,7 @@
- Updated dependencies [a828271d]
- Updated dependencies [24b9be02]
- Updated dependencies [e75c0a3b]
- @verdaccio/fastify-migration@6.0.0-6-next.17
- @verdaccio/server-fastify@6.0.0-6-next.17
- @verdaccio/core@6.0.0-6-next.4
- @verdaccio/logger@6.0.0-6-next.8
- @verdaccio/node-api@6.0.0-6-next.25
@ -112,7 +112,7 @@
- Updated dependencies [f86c31ed]
- Updated dependencies [20c9e43e]
- @verdaccio/fastify-migration@6.0.0-6-next.16
- @verdaccio/server-fastify@6.0.0-6-next.16
- @verdaccio/config@6.0.0-6-next.11
- @verdaccio/node-api@6.0.0-6-next.24
@ -129,7 +129,7 @@
- @verdaccio/logger@6.0.0-6-next.7
- @verdaccio/node-api@6.0.0-6-next.23
- @verdaccio/config@6.0.0-6-next.10
- @verdaccio/fastify-migration@6.0.0-6-next.15
- @verdaccio/server-fastify@6.0.0-6-next.15
## 6.0.0-6-next.23
@ -149,7 +149,7 @@
- Updated dependencies [b702ea36]
- Updated dependencies [154b2ecd]
- @verdaccio/config@6.0.0-6-next.9
- @verdaccio/fastify-migration@6.0.0-6-next.14
- @verdaccio/server-fastify@6.0.0-6-next.14
- @verdaccio/logger@6.0.0-6-next.6
- @verdaccio/node-api@6.0.0-6-next.22
@ -159,7 +159,7 @@
- Updated dependencies [2c594910]
- @verdaccio/logger@6.0.0-6-next.5
- @verdaccio/fastify-migration@6.0.0-6-next.13
- @verdaccio/server-fastify@6.0.0-6-next.13
- @verdaccio/node-api@6.0.0-6-next.21
## 6.0.0-6-next.21
@ -203,7 +203,7 @@
- Updated dependencies [459b6fa7]
- @verdaccio/config@6.0.0-6-next.8
- @verdaccio/fastify-migration@6.0.0-6-next.12
- @verdaccio/server-fastify@6.0.0-6-next.12
- @verdaccio/node-api@6.0.0-6-next.20
- @verdaccio/logger@6.0.0-6-next.4
@ -212,7 +212,7 @@
### Patch Changes
- Updated dependencies [df0da3d6]
- @verdaccio/fastify-migration@6.0.0-6-next.11
- @verdaccio/server-fastify@6.0.0-6-next.11
- @verdaccio/node-api@6.0.0-6-next.19
## 6.0.0-6-next.19
@ -236,7 +236,7 @@
### Patch Changes
- Updated dependencies [55ee3fdd]
- @verdaccio/fastify-migration@6.0.0-6-next.10
- @verdaccio/server-fastify@6.0.0-6-next.10
- @verdaccio/config@6.0.0-6-next.7
- @verdaccio/node-api@6.0.0-6-next.17
@ -250,7 +250,7 @@
### Patch Changes
- @verdaccio/fastify-migration@6.0.0-6-next.9
- @verdaccio/server-fastify@6.0.0-6-next.9
- @verdaccio/logger@6.0.0-6-next.4
- @verdaccio/node-api@6.0.0-6-next.15
@ -258,7 +258,7 @@
### Patch Changes
- @verdaccio/fastify-migration@6.0.0-6-next.9
- @verdaccio/server-fastify@6.0.0-6-next.9
- @verdaccio/logger@6.0.0-6-next.4
- @verdaccio/node-api@6.0.0-6-next.14
@ -291,7 +291,7 @@
- Updated dependencies [19d272d1]
- @verdaccio/node-api@6.0.0-6-next.12
- @verdaccio/fastify-migration@6.0.0-6-next.9
- @verdaccio/server-fastify@6.0.0-6-next.9
- @verdaccio/logger@6.0.0-6-next.4
## 6.0.0-6-next.11

@ -48,7 +48,6 @@
"@verdaccio/config": "workspace:6.0.0-6-next.14",
"@verdaccio/logger": "workspace:6.0.0-6-next.11",
"@verdaccio/node-api": "workspace:6.0.0-6-next.32",
"@verdaccio/fastify-migration": "workspace:6.0.0-6-next.23",
"clipanion": "3.1.0",
"envinfo": "7.8.1",
"kleur": "3.0.3",

@ -2,7 +2,6 @@ import { Cli } from 'clipanion';
import { warningUtils } from '@verdaccio/core';
import { FastifyServer } from './commands/FastifyServer';
import { InfoCommand } from './commands/info';
import { InitCommand } from './commands/init';
import { VersionCommand } from './commands/version';
@ -30,7 +29,6 @@ const cli = new Cli({
cli.register(InfoCommand);
cli.register(InitCommand);
cli.register(VersionCommand);
cli.register(FastifyServer);
cli.runExit(args, Cli.defaultContext);
process.on('uncaughtException', function (err) {

@ -1,58 +0,0 @@
import { Command, Option } from 'clipanion';
import { findConfigFile, parseConfigFile } from '@verdaccio/config';
import server from '@verdaccio/fastify-migration';
import { logger, setup } from '@verdaccio/logger';
import { ConfigYaml } from '@verdaccio/types';
export const DEFAULT_PROCESS_NAME: string = 'verdaccio';
/**
* This command is intended to run the server with Fastify
* as a migration step.
* More info: https://github.com/verdaccio/verdaccio/discussions/2155
* To try out.
* pnpm debug:fastify
*/
export class FastifyServer extends Command {
public static paths = [['fastify-server']];
private port = Option.String('-l,-p,--listen,--port', {
description: 'host:port number to listen on (default: localhost:4873)',
});
private config = Option.String('-c,--config', {
description: 'use this configuration file (default: ./config.yaml)',
});
private initLogger(logConfig: ConfigYaml) {
try {
if (logConfig.log) {
throw Error('logger as array not longer supported');
}
// FUTURE: remove fallback when is ready
setup(logConfig.log);
} catch (err: any) {
throw new Error(err);
}
}
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;
// FIXME: need a way to get version of the package.
// const { version, name } = require('../../package.json');
const ser = await server({ logger, config: configParsed });
// FIXME: harcoded, this would need to come from the configuration and the --listen flag.
await ser.listen(process.env.PORT || 4873);
} catch (err: any) {
console.error(err);
process.exit(1);
}
}
}

@ -23,14 +23,16 @@ export {
DEFAULT_USER,
USERS,
} from './constants';
const validationUtils = validatioUtils;
export {
fileUtils,
pkgUtils,
searchUtils,
streamUtils,
errorUtils,
// TODO: remove this typo
validatioUtils,
validationUtils,
constants,
pluginUtils,
warningUtils,

@ -1,3 +0,0 @@
## Experimental packages
- `fastify-server`: Fastify experimental implementation

@ -1,42 +0,0 @@
import buildDebug from 'debug';
import { FastifyInstance } from 'fastify';
const debug = buildDebug('verdaccio:api:dist-tags');
async function distTagsRoute(fastify: FastifyInstance) {
fastify.get('/-/package/:packageName/dist-tags', async (request, reply) => {
// @ts-ignore
const { packageName } = request.params;
debug('dist-tags: response %o', packageName);
const requestOptions = {
protocol: request.protocol,
headers: request.headers as any,
host: request.hostname,
remoteAddress: request.socket.remoteAddress,
};
const manifest = fastify.storage.getPackageByOptions({
name: packageName,
uplinksLook: true,
keepUpLinkData: true,
requestOptions,
});
reply.code(fastify.statusCode.OK).send(manifest[fastify.constants.DIST_TAGS]);
});
fastify.post('/-/package/:packageName/dist-tags', async (request) => {
// @ts-ignore
const { packageName } = request.params;
// @ts-ignore
await fastify.storage.mergeTags(packageName, request.body);
return { ok: fastify.constants.API_MESSAGE.TAG_UPDATED };
});
fastify.delete('/-/package/:packageName/dist-tags', async (request, reply) => {
// @ts-ignore
// const { packageName } = request.params;
reply.code(fastify.statusCode.NOT_FOUND);
});
}
export default distTagsRoute;

@ -1,52 +0,0 @@
import buildDebug from 'debug';
import { FastifyInstance } from 'fastify';
import { Package, Version } from '@verdaccio/types';
const debug = buildDebug('verdaccio:web:api:sidebar');
export type $SidebarPackage = Package & { latest: Version };
async function manifestRoute(fastify: FastifyInstance) {
fastify.get('/:packageName', async (request) => {
// @ts-ignore
const { packageName } = request.params;
const storage = fastify.storage;
debug('pkg name %s ', packageName);
const data = await storage?.getPackageByOptions({
name: packageName,
// remove on refactor getPackageByOptions
// @ts-ignore
req: request.raw,
uplinksLook: true,
requestOptions: {
protocol: request.protocol,
headers: request.headers as any,
host: request.hostname,
},
});
return data;
});
fastify.get('/:packageName/:version', async (request) => {
// @ts-ignore
const { packageName, version } = request.params;
const storage = fastify.storage;
debug('pkg name %s, with version / tag: %s ', packageName, version);
const data = await storage?.getPackageByOptions({
name: packageName,
// remove on refactor getPackageByOptions
// @ts-ignore
req: request.raw,
version,
uplinksLook: true,
requestOptions: {
protocol: request.protocol,
headers: request.headers as any,
host: request.hostname,
},
});
return data;
});
}
export default manifestRoute;

@ -1,25 +0,0 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import buildDebug from 'debug';
import { FastifyInstance } from 'fastify';
const debug = buildDebug('verdaccio:api:tarball');
async function tarballRoute(fastify: FastifyInstance) {
fastify.get('/:package/-/:filename', async (request, reply) => {
// @ts-ignore
const { package: pkg, filename } = request.params;
debug('stream tarball for %s@%s', pkg, filename);
// const stream = fastify.storage.getTarball(pkg, filename);
// return reply.send(stream);
});
fastify.get('/:scopedPackage/-/:scope/:filename', async (request, reply) => {
// @ts-ignore
const { scopedPackage, filename } = request.params;
debug('stream scope tarball for %s@%s', scopedPackage, filename);
// const stream = fastify.storage.getTarball(scopedPackage, filename);
// return reply.send(stream);
});
}
export default tarballRoute;

@ -4,7 +4,7 @@ module.exports = Object.assign({}, config, {
coverageThreshold: {
global: {
// FIXME: increase to 90
lines: 52,
lines: 40,
},
},
});

@ -43,6 +43,7 @@
"@verdaccio/config": "workspace:6.0.0-6-next.14",
"@verdaccio/logger": "workspace:6.0.0-6-next.11",
"@verdaccio/server": "workspace:6.0.0-6-next.31",
"@verdaccio/server-fastify": "workspace:6.0.0-6-next.23",
"core-js": "3.20.3",
"debug": "4.3.3",
"lodash": "4.17.21"

@ -11,6 +11,7 @@ import { findConfigFile, parseConfigFile } from '@verdaccio/config';
import { API_ERROR } from '@verdaccio/core';
import { setup } from '@verdaccio/logger';
import server from '@verdaccio/server';
import fastifyServer from '@verdaccio/server-fastify';
import { ConfigYaml, HttpsConfKeyCert, HttpsConfPfx } from '@verdaccio/types';
import { getListListenAddresses } from './cli-utils';
@ -110,49 +111,61 @@ export async function initServer(
const [addr] = getListListenAddresses(port, config.listen);
const logger = setup(config?.log as any);
displayExperimentsInfoBox(config.flags);
const app = await server(config);
const serverFactory = createServerFactory(config, addr, app);
serverFactory
.listen(addr.port || addr.path, addr.host, (): void => {
// send a message for test
if (isFunction(process.send)) {
process.send({
verdaccio_started: true,
});
let app;
if (process.env.VERDACCIO_SERVER === 'fastify') {
app = await fastifyServer(config);
app.listen({ port: addr.port, host: addr.host }, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
const addressServer = `${
addr.path
? url.format({
protocol: 'unix',
pathname: addr.path,
})
: url.format({
protocol: addr.proto,
hostname: addr.host,
port: addr.port,
pathname: '/',
})
}`;
logger.info(`http address ${addressServer}`);
logger.info(`version: ${version}`);
resolve();
})
.on('error', function (err): void {
reject(err);
process.exitCode = 1;
});
} else {
app = await server(config);
const serverFactory = createServerFactory(config, addr, app);
serverFactory
.listen(addr.port || addr.path, addr.host, (): void => {
// send a message for test
if (isFunction(process.send)) {
process.send({
verdaccio_started: true,
});
}
const addressServer = `${
addr.path
? url.format({
protocol: 'unix',
pathname: addr.path,
})
: url.format({
protocol: addr.proto,
hostname: addr.host,
port: addr.port,
pathname: '/',
})
}`;
logger.info(`http address ${addressServer}`);
logger.info(`version: ${version}`);
resolve();
})
.on('error', function (err): void {
reject(err);
process.exitCode = 1;
});
function handleShutdownGracefully() {
logger.warn('received shutdown signal - closing server gracefully...');
serverFactory.close(() => {
logger.info('server closed.');
process.exit(0);
});
}
function handleShutdownGracefully() {
logger.warn('received shutdown signal - closing server gracefully...');
serverFactory.close(() => {
logger.info('server closed.');
process.exit(0);
});
}
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
// Use once() so that receiving double signals exit the app.
process.once(signal, handleShutdownGracefully);
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
// Use once() so that receiving double signals exit the app.
process.once(signal, handleShutdownGracefully);
}
}
});
}

@ -20,7 +20,10 @@
"path": "../mock"
},
{
"path": "../server"
"path": "../server/express"
},
{
"path": "../server/fastify"
}
]
}

@ -1,3 +0,0 @@
{
"extends": "../../.babelrc"
}

@ -140,7 +140,7 @@ export default (async function (configHash: ConfigYaml): Promise<any> {
// register middleware plugins
const plugin_params = {
config: config,
logger: logger,
logger,
};
const filters = loadPlugin(
config,

@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base",
"extends": "../../../tsconfig.base",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./build"

@ -0,0 +1,50 @@
{
"extends": "../../../tsconfig.reference.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./build"
},
"include": ["src/**/*", "types/*.d.ts"],
"exclude": ["src/**/*.test.ts"],
"references": [
{
"path": "../../api"
},
{
"path": "../../auth"
},
{
"path": "../../config"
},
{
"path": "../../core/commons-api"
},
{
"path": "../../loaders"
},
{
"path": "../../logger"
},
{
"path": "../../middleware"
},
{
"path": "../../mock"
},
{
"path": "../../plugins/audit"
},
{
"path": "../../proxy"
},
{
"path": "../../store"
},
{
"path": "../../utils"
},
{
"path": "../../web"
}
]
}

@ -0,0 +1,3 @@
{
"extends": "../../../.babelrc"
}

@ -1,4 +1,4 @@
# @verdaccio/fastify-migration
# @verdaccio/server-fastify
## 6.0.0-6-next.23

@ -1,7 +1,7 @@
{
"name": "@verdaccio/fastify-migration",
"name": "@verdaccio/server-fastify",
"version": "6.0.0-6-next.23",
"description": "Fastify server migration package",
"description": "fastify server api implementation",
"keywords": [
"private",
"package",
@ -44,8 +44,8 @@
"@verdaccio/readme": "workspace:11.0.0-6-next.4",
"core-js": "3.20.3",
"debug": "4.3.3",
"fastify": "3.27.0",
"fastify-plugin": "3.0.0",
"fastify": "4.3.0",
"fastify-plugin": "4.1.0",
"lodash": "4.17.21"
},
"devDependencies": {

@ -0,0 +1,52 @@
import buildDebug from 'debug';
import { FastifyInstance } from 'fastify';
import { MergeTags } from '@verdaccio/types';
const debug = buildDebug('verdaccio:fastify:dist-tags');
interface ParamsInterface {
packageName: string;
}
async function distTagsRoute(fastify: FastifyInstance) {
fastify.get<{ Params: ParamsInterface }>(
'/-/package/:packageName/dist-tags',
async (request, reply) => {
// @ts-ignore
const { packageName } = request.params;
debug('dist-tags: response %o', packageName);
const requestOptions = {
protocol: request.protocol,
headers: request.headers as any,
host: request.hostname,
remoteAddress: request.socket.remoteAddress,
};
const manifest = fastify.storage.getPackageByOptions({
name: packageName,
uplinksLook: true,
keepUpLinkData: true,
requestOptions,
});
reply.code(fastify.statusCode.OK).send(manifest[fastify.constants.DIST_TAGS]);
}
);
fastify.post<{ Params: ParamsInterface; Body: MergeTags }>(
'/-/package/:packageName/dist-tags',
async (request) => {
const { packageName } = request.params;
await fastify.storage.mergeTagsNext(packageName, request.body);
return { ok: fastify.constants.API_MESSAGE.TAG_UPDATED };
}
);
fastify.delete('/-/package/:packageName/dist-tags', async (request, reply) => {
// @ts-ignore
// const { packageName } = request.params;
reply.code(fastify.statusCode.NOT_FOUND);
});
}
export default distTagsRoute;

@ -0,0 +1,61 @@
import buildDebug from 'debug';
import { FastifyInstance } from 'fastify';
import { Package, Version } from '@verdaccio/types';
const debug = buildDebug('verdaccio:fastify:api:sidebar');
export type $SidebarPackage = Package & { latest: Version };
interface ParamsInterface {
name: string;
version: string;
}
async function manifestRoute(fastify: FastifyInstance) {
fastify.get<{ Params: ParamsInterface }>('/:name', async (request) => {
const { name } = request.params;
const storage = fastify.storage;
debug('pkg name %s ', name);
const data = await storage?.getPackageByOptions({
name,
// @ts-ignore
uplinksLook: true,
requestOptions: {
protocol: request.protocol,
headers: request.headers as any,
host: request.hostname,
},
});
return data;
});
interface QueryInterface {
write: string;
}
fastify.get<{ Params: ParamsInterface; Querystring: QueryInterface }>(
'/:packageName/:version',
async (request) => {
const { name, version } = request.params;
const storage = fastify.storage;
const write = request.query.write === 'true';
debug('pkg name %s, with version / tag: %s ', name, version);
const requestOptions = {
protocol: request.protocol,
headers: request.headers as any,
host: request.hostname,
remoteAddress: request.socket.remoteAddress,
byPassCache: write,
};
const data = await storage?.getPackageByOptions({
name,
version,
uplinksLook: true,
requestOptions,
});
return data;
}
);
}
export default manifestRoute;

@ -7,9 +7,7 @@ import { logger } from '@verdaccio/logger';
async function pingRoute(fastify: FastifyInstance) {
fastify.get('/-/ping', async () => {
logger.http('ping endpoint');
console.log('-storage->', fastify.storage);
console.log('-config->', fastify.configInstance);
logger.http('ping');
return {};
});
}

Some files were not shown because too many files have changed in this diff Show More