Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@verdaccio/web

Package Overview
Dependencies
Maintainers
4
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@verdaccio/web

web ui middleware

  • 6.0.0-6-next.63
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.4K
decreased by-22.41%
Maintainers
4
Weekly downloads
 
Created
Source

import buildDebug from 'debug'; import { Router } from 'express';

import { Auth } from '@verdaccio/auth'; import { HEADERS, HEADER_TYPE } from '@verdaccio/core'; import { logger } from '@verdaccio/logger'; import { $NextFunctionVer, $RequestExtend, $ResponseExtend, allow } from '@verdaccio/middleware'; import { Storage } from '@verdaccio/store'; import { Manifest } from '@verdaccio/types';

import { AuthorAvatar, addScope } from '../web-utils';

export { $RequestExtend, $ResponseExtend, $NextFunctionVer }; // Was required by other packages

// TODO: review this type, should be on @verdacid/types export type PackageExt = Manifest & { author: AuthorAvatar; dist?: { tarball: string } }; export const NOT_README_FOUND = 'ERROR: No README data found!'; const debug = buildDebug('verdaccio:web:api:readme'); const getReadme = (readme) => { if (typeof readme === 'string' && readme.length === 0) { return NOT_README_FOUND; } if (typeof readme !== 'string') { return NOT_README_FOUND; } else { return readme; } };

function addReadmeWebApi(storage: Storage, auth: Auth): Router { debug('initialized readme web api'); const can = allow(auth, { beforeAll: (a, b) => logger.trace(a, b), afterAll: (a, b) => logger.trace(a, b), }); const pkgRouter = Router(); /* eslint new-cap: 0 */

pkgRouter.get( '/package/readme/(@:scope/)?:package/:version?', can('access'), async function ( req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer ): Promise { debug('readme hit'); const name = req.params.scope ? addScope(req.params.scope, req.params.package) : req.params.package; debug('readme name %o', name); const requestOptions = { protocol: req.protocol, headers: req.headers as any, // FIXME: if we migrate to req.hostname, the port is not longer included. host: req.host, remoteAddress: req.socket.remoteAddress, }; try { const manifest = (await storage.getPackageByOptions({ name, uplinksLook: true, abbreviated: false, requestOptions, })) as Manifest; debug('readme pkg %o', manifest?.name); res.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_PLAIN_UTF8); next(getReadme(manifest.readme)); } catch (err) { next(err); } } ); return pkgRouter; }

export default addReadmeWebApi;

Keywords

FAQs

Package last updated on 20 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc