mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-04-15 03:02:51 -05:00
chore: middleware package update (#5126)
This commit is contained in:
parent
dd2fa34e1f
commit
66bc2843e1
5 changed files with 26 additions and 15 deletions
6
.changeset/violet-baboons-beg.md
Normal file
6
.changeset/violet-baboons-beg.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
'@verdaccio/middleware': patch
|
||||
'@verdaccio/web': patch
|
||||
---
|
||||
|
||||
chore: middleware package update
|
|
@ -8,6 +8,7 @@ import { isURLhasValidProtocol } from '@verdaccio/url';
|
|||
|
||||
import { setSecurityWebHeaders } from './security';
|
||||
import renderHTML from './utils/renderHTML';
|
||||
import { WebUrlsNamespace } from './web-urls';
|
||||
|
||||
const debug = buildDebug('verdaccio:web:render');
|
||||
|
||||
|
@ -35,7 +36,7 @@ export function renderWebMiddleware(config, tokenMiddleware, pluginOptions) {
|
|||
router.use(setSecurityWebHeaders);
|
||||
|
||||
// any match within the static is routed to the file system
|
||||
router.get('/-/static/*', function (req, res, next) {
|
||||
router.get(WebUrlsNamespace.static + '*', function (req, res, next) {
|
||||
const filename = req.params[0];
|
||||
let file = `${staticPath}/${filename}`;
|
||||
if (filename === 'favicon.ico' && config?.web?.favicon) {
|
||||
|
@ -64,7 +65,7 @@ export function renderWebMiddleware(config, tokenMiddleware, pluginOptions) {
|
|||
) {
|
||||
// Note: `path.join` will break on Windows, because it transforms `/` to `\`
|
||||
// Use POSIX version `path.posix.join` instead.
|
||||
logo = path.posix.join('/-/static/', path.basename(logo));
|
||||
logo = path.posix.join(WebUrlsNamespace.static, path.basename(logo));
|
||||
router.get(logo, function (_req, res, next) {
|
||||
// @ts-ignore
|
||||
debug('serve custom logo web:%s - local:%s', logo, absoluteLocalFile);
|
||||
|
@ -92,12 +93,12 @@ export function renderWebMiddleware(config, tokenMiddleware, pluginOptions) {
|
|||
config.web.logoDark = logoDark;
|
||||
}
|
||||
|
||||
router.get('/-/web/:section/*', function (req, res) {
|
||||
router.get(WebUrlsNamespace.web + ':section/*', function (req, res) {
|
||||
renderHTML(config, manifest, manifestFiles, req, res);
|
||||
debug('render html section');
|
||||
});
|
||||
|
||||
router.get('/', function (req, res) {
|
||||
router.get(WebUrlsNamespace.root, function (req, res) {
|
||||
renderHTML(config, manifest, manifestFiles, req, res);
|
||||
debug('render root');
|
||||
});
|
||||
|
|
|
@ -2,14 +2,15 @@ import express from 'express';
|
|||
|
||||
import { renderWebMiddleware } from './render-web';
|
||||
import { webAPIMiddleware } from './web-api';
|
||||
import { WebUrlsNamespace } from './web-urls';
|
||||
|
||||
export default (config, middlewares, pluginOptions): any => {
|
||||
// eslint-disable-next-line new-cap
|
||||
const router = express.Router();
|
||||
const { tokenMiddleware, webEndpointsApi } = middlewares;
|
||||
// render web
|
||||
router.use('/', renderWebMiddleware(config, tokenMiddleware, pluginOptions));
|
||||
// web endpoints, search, packages, etc
|
||||
router.use('/-/verdaccio/', webAPIMiddleware(tokenMiddleware, webEndpointsApi));
|
||||
router.use(WebUrlsNamespace.root, renderWebMiddleware(config, tokenMiddleware, pluginOptions));
|
||||
// web endpoints: search, packages, readme, sidebar, etc
|
||||
router.use(WebUrlsNamespace.endpoints, webAPIMiddleware(tokenMiddleware, webEndpointsApi));
|
||||
return router;
|
||||
};
|
||||
|
|
|
@ -16,7 +16,10 @@ export enum WebUrls {
|
|||
* Enum for web urls namespace, used on the web middleware
|
||||
*/
|
||||
export enum WebUrlsNamespace {
|
||||
root = '/-/verdaccio/',
|
||||
root = '/',
|
||||
static = '/-/static/',
|
||||
endpoints = '/-/verdaccio/',
|
||||
web = '/-/web/',
|
||||
data = '/data/',
|
||||
sec = '/sec/',
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Router } from 'express';
|
||||
|
||||
import { rateLimit } from '@verdaccio/middleware';
|
||||
import { WebUrlsNamespace, rateLimit } from '@verdaccio/middleware';
|
||||
|
||||
import { hasLogin } from '../web-utils';
|
||||
import packageApi from './package';
|
||||
|
@ -12,19 +12,19 @@ import user from './user';
|
|||
export default (auth, storage, config) => {
|
||||
const route = Router(); /* eslint new-cap: 0 */
|
||||
route.use(
|
||||
'/data/',
|
||||
WebUrlsNamespace.data,
|
||||
rateLimit({
|
||||
windowMs: 2 * 60 * 1000, // 2 minutes
|
||||
max: 5000, // limit each IP to 1000 requests per windowMs
|
||||
...config?.web?.rateLimit,
|
||||
})
|
||||
);
|
||||
route.use('/data/', packageApi(storage, auth, config));
|
||||
route.use('/data/', search(storage, auth));
|
||||
route.use('/data/', sidebar(config, storage, auth));
|
||||
route.use('/data/', readme(storage, auth));
|
||||
route.use(WebUrlsNamespace.data, packageApi(storage, auth, config));
|
||||
route.use(WebUrlsNamespace.data, search(storage, auth));
|
||||
route.use(WebUrlsNamespace.data, sidebar(config, storage, auth));
|
||||
route.use(WebUrlsNamespace.data, readme(storage, auth));
|
||||
if (hasLogin(config)) {
|
||||
route.use('/sec/', user(auth, config));
|
||||
route.use(WebUrlsNamespace.sec, user(auth, config));
|
||||
}
|
||||
return route;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue