2021-10-29 10:33:05 -05:00
|
|
|
import bodyParser from 'body-parser';
|
2021-06-12 02:25:53 -05:00
|
|
|
import express, { Router } from 'express';
|
2021-10-29 10:33:05 -05:00
|
|
|
|
2022-10-11 16:06:55 -05:00
|
|
|
import { Auth } from '@verdaccio/auth';
|
2020-09-16 23:48:16 -05:00
|
|
|
import {
|
2021-10-29 10:33:05 -05:00
|
|
|
antiLoop,
|
|
|
|
encodeScopePackage,
|
2020-09-16 23:48:16 -05:00
|
|
|
match,
|
|
|
|
validateName,
|
|
|
|
validatePackage,
|
|
|
|
} from '@verdaccio/middleware';
|
2021-09-08 12:06:37 -05:00
|
|
|
import { Storage } from '@verdaccio/store';
|
2020-03-03 17:59:19 -05:00
|
|
|
import { Config } from '@verdaccio/types';
|
2018-03-10 15:09:04 -05:00
|
|
|
|
2020-03-03 17:59:19 -05:00
|
|
|
import distTags from './dist-tags';
|
2021-10-29 10:33:05 -05:00
|
|
|
import pkg from './package';
|
|
|
|
import ping from './ping';
|
2020-03-03 17:59:19 -05:00
|
|
|
import publish from './publish';
|
|
|
|
import search from './search';
|
|
|
|
import stars from './stars';
|
2021-10-29 10:33:05 -05:00
|
|
|
import user from './user';
|
2020-03-03 17:59:19 -05:00
|
|
|
import profile from './v1/profile';
|
2020-08-13 16:27:00 -05:00
|
|
|
import v1Search from './v1/search';
|
2021-10-29 10:33:05 -05:00
|
|
|
import token from './v1/token';
|
|
|
|
import whoami from './whoami';
|
2017-06-21 12:02:52 -05:00
|
|
|
|
2022-10-11 16:06:55 -05:00
|
|
|
export default function (config: Config, auth: Auth, storage: Storage): Router {
|
2017-06-21 12:02:52 -05:00
|
|
|
/* eslint new-cap:off */
|
|
|
|
const app = express.Router();
|
|
|
|
/* eslint new-cap:off */
|
|
|
|
|
|
|
|
// validate all of these params as a package name
|
|
|
|
// this might be too harsh, so ask if it causes trouble
|
2018-03-10 17:13:26 -05:00
|
|
|
app.param('package', validatePackage);
|
2018-04-30 08:41:04 -05:00
|
|
|
app.param('filename', validateName);
|
|
|
|
app.param('tag', validateName);
|
|
|
|
app.param('version', validateName);
|
|
|
|
app.param('revision', validateName);
|
|
|
|
app.param('token', validateName);
|
2017-06-21 12:02:52 -05:00
|
|
|
|
|
|
|
// these can't be safely put into express url for some reason
|
|
|
|
// TODO: For some reason? what reason?
|
|
|
|
app.param('_rev', match(/^-rev$/));
|
|
|
|
app.param('org_couchdb_user', match(/^org\.couchdb\.user:/));
|
2018-04-30 08:13:54 -05:00
|
|
|
app.use(auth.apiJWTmiddleware());
|
2020-07-16 14:59:21 -05:00
|
|
|
app.use(bodyParser.json({ strict: false, limit: config.max_body_size || '10mb' }));
|
2020-03-03 17:59:19 -05:00
|
|
|
// @ts-ignore
|
2018-10-06 17:32:17 -05:00
|
|
|
app.use(antiLoop(config));
|
2017-06-21 12:02:52 -05:00
|
|
|
// encode / in a scoped package name to be matched as a single parameter in routes
|
|
|
|
app.use(encodeScopePackage);
|
|
|
|
// for "npm whoami"
|
|
|
|
whoami(app);
|
2021-12-12 12:00:19 -05:00
|
|
|
pkg(app, auth, storage);
|
2022-09-17 12:29:40 -05:00
|
|
|
profile(app, auth, config);
|
2021-09-08 12:06:37 -05:00
|
|
|
// @deprecated endpoint, 404 by default
|
|
|
|
search(app);
|
2018-08-21 01:05:34 -05:00
|
|
|
user(app, auth, config);
|
2017-06-21 12:02:52 -05:00
|
|
|
distTags(app, auth, storage);
|
2022-07-29 13:51:45 -05:00
|
|
|
publish(app, auth, storage);
|
2017-06-21 12:02:52 -05:00
|
|
|
ping(app);
|
2019-03-11 10:37:17 -05:00
|
|
|
stars(app, storage);
|
2021-09-08 12:06:37 -05:00
|
|
|
// @ts-ignore
|
|
|
|
v1Search(app, auth, storage);
|
|
|
|
token(app, auth, storage, config);
|
2017-06-21 12:02:52 -05:00
|
|
|
return app;
|
2018-03-10 17:13:26 -05:00
|
|
|
}
|