2019-07-16 08:40:01 +02:00
|
|
|
import { IAuth, IStorageHandler } from '../../../types';
|
|
|
|
import { Config } from '@verdaccio/types';
|
2019-09-07 15:46:50 -07:00
|
|
|
import _ from 'lodash';
|
2018-03-10 21:09:04 +01:00
|
|
|
|
|
|
|
import express from 'express';
|
|
|
|
import bodyParser from 'body-parser';
|
|
|
|
import whoami from './api/whoami';
|
|
|
|
import ping from './api/ping';
|
|
|
|
import user from './api/user';
|
|
|
|
import distTags from './api/dist-tags';
|
|
|
|
import publish from './api/publish';
|
|
|
|
import search from './api/search';
|
|
|
|
import pkg from './api/package';
|
2019-03-11 23:37:17 +08:00
|
|
|
import stars from './api/stars';
|
2018-10-12 11:07:55 +02:00
|
|
|
import profile from './api/v1/profile';
|
2019-09-07 15:46:50 -07:00
|
|
|
import token from './api/v1/token';
|
2018-03-10 21:09:04 +01:00
|
|
|
|
2018-10-07 04:02:17 +05:30
|
|
|
const { match, validateName, validatePackage, encodeScopePackage, antiLoop } = require('../middleware');
|
2017-06-22 01:02:52 +08:00
|
|
|
|
2018-03-11 16:27:16 +01:00
|
|
|
export default function(config: Config, auth: IAuth, storage: IStorageHandler) {
|
2017-06-22 01:02:52 +08: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-11 16:27:16 +01:00
|
|
|
// $FlowFixMe
|
2018-03-10 23:13:26 +01:00
|
|
|
app.param('package', validatePackage);
|
2018-03-11 16:27:16 +01:00
|
|
|
// $FlowFixMe
|
2018-04-30 15:41:04 +02:00
|
|
|
app.param('filename', validateName);
|
|
|
|
app.param('tag', validateName);
|
|
|
|
app.param('version', validateName);
|
|
|
|
app.param('revision', validateName);
|
|
|
|
app.param('token', validateName);
|
2017-06-22 01:02:52 +08: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:/));
|
|
|
|
app.param('anything', match(/.*/));
|
|
|
|
|
2018-04-30 15:13:54 +02:00
|
|
|
app.use(auth.apiJWTmiddleware());
|
2018-10-01 07:06:30 +02:00
|
|
|
app.use(bodyParser.json({ strict: false, limit: config.max_body_size || '10mb' }));
|
2018-10-07 04:02:17 +05:30
|
|
|
app.use(antiLoop(config));
|
2017-06-22 01:02:52 +08:00
|
|
|
// encode / in a scoped package name to be matched as a single parameter in routes
|
|
|
|
app.use(encodeScopePackage);
|
|
|
|
// for "npm whoami"
|
|
|
|
whoami(app);
|
|
|
|
pkg(app, auth, storage, config);
|
2018-10-12 11:07:55 +02:00
|
|
|
profile(app, auth);
|
2017-06-22 01:02:52 +08:00
|
|
|
search(app, auth, storage);
|
2018-08-21 08:05:34 +02:00
|
|
|
user(app, auth, config);
|
2017-06-22 01:02:52 +08:00
|
|
|
distTags(app, auth, storage);
|
|
|
|
publish(app, auth, storage, config);
|
|
|
|
ping(app);
|
2019-03-11 23:37:17 +08:00
|
|
|
stars(app, storage);
|
2019-09-07 15:46:50 -07:00
|
|
|
if (_.get(config, 'experiments.token') === true) {
|
|
|
|
token(app, auth, storage, config);
|
|
|
|
}
|
2017-06-22 01:02:52 +08:00
|
|
|
return app;
|
2018-03-10 23:13:26 +01:00
|
|
|
}
|