mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-30 22:34:10 -05:00
refactor: apply flow and imports es6
This commit is contained in:
parent
1d5a2c8214
commit
76fe6cb5d7
10 changed files with 37 additions and 41 deletions
|
@ -1,12 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
const Middleware = require('../../web/middleware');
|
||||
const mime = require('mime');
|
||||
const _ = require('lodash');
|
||||
|
||||
const media = Middleware.media;
|
||||
|
||||
module.exports = function(route, auth, storage) {
|
||||
export default function(route, auth, storage) {
|
||||
const can = Middleware.allow(auth);
|
||||
const tag_package_version = function(req, res, next) {
|
||||
if (_.isString(req.body) === false) {
|
||||
|
@ -71,4 +69,4 @@ module.exports = function(route, auth, storage) {
|
|||
return next({ok: 'tags updated'});
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ const createError = require('http-errors');
|
|||
const Middleware = require('../../web/middleware');
|
||||
const Utils = require('../../../lib/utils');
|
||||
|
||||
module.exports = function(route, auth, storage, config) {
|
||||
export default function(route, auth, storage, config) {
|
||||
const can = Middleware.allow(auth);
|
||||
// TODO: anonymous user?
|
||||
route.get('/:package/:version?', can('access'), function(req, res, next) {
|
||||
|
@ -56,4 +56,4 @@ module.exports = function(route, auth, storage, config) {
|
|||
res.header('Content-Type', 'application/octet-stream');
|
||||
stream.pipe(res);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
'use strict';
|
||||
// @flow
|
||||
|
||||
module.exports = function(route) {
|
||||
route.get('/-/ping', function(req, res, next) {
|
||||
import type {Router} from 'express';
|
||||
import type {$RequestExtend, $ResponseExtend, $NextFunctionVer} from '../../../../types';
|
||||
|
||||
export default function(route: Router) {
|
||||
route.get('/-/ping', function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
next({});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const Path = require('path');
|
||||
const createError = require('http-errors');
|
||||
|
@ -13,7 +11,7 @@ const media = Middleware.media;
|
|||
const expect_json = Middleware.expect_json;
|
||||
const notify = Notify.notify;
|
||||
|
||||
module.exports = function(router, auth, storage, config) {
|
||||
export default function(router, auth, storage, config) {
|
||||
const can = Middleware.allow(auth);
|
||||
|
||||
// publishing a package
|
||||
|
@ -185,4 +183,4 @@ module.exports = function(router, auth, storage, config) {
|
|||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = function(route, auth, storage) {
|
||||
export default function(route, auth, storage) {
|
||||
// searching packages
|
||||
route.get('/-/all(\/since)?', function(req, res) {
|
||||
let received_end = false;
|
||||
|
@ -96,4 +94,4 @@ module.exports = function(route, auth, storage) {
|
|||
check_finish();
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import {ErrorCode} from '../../../lib/utils';
|
|||
import _ from 'lodash';
|
||||
import Cookies from 'cookies';
|
||||
|
||||
module.exports = function(route: Router, auth: IAuth) {
|
||||
export default function(route: Router, auth: IAuth) {
|
||||
route.get('/-/user/:org_couchdb_user', function(req: $RequestExtend, res: $Response, next: $NextFunctionVer) {
|
||||
res.status(200);
|
||||
next({
|
||||
|
@ -70,4 +70,4 @@ module.exports = function(route: Router, auth: IAuth) {
|
|||
roles: [],
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import type {$Response, Router} from 'express';
|
||||
import type {$RequestExtend, $NextFunctionVer} from '../../../../types';
|
||||
|
||||
module.exports = function(route: Router) {
|
||||
export default function(route: Router) {
|
||||
route.get('/whoami', (req: $RequestExtend, res: $Response, next: $NextFunctionVer): void => {
|
||||
if (req.headers.referer === 'whoami') {
|
||||
next({username: req.remote_user.name});
|
||||
|
@ -15,4 +15,4 @@ module.exports = function(route: Router) {
|
|||
route.get('/-/whoami', (req: $RequestExtend, res: $Response, next: $NextFunctionVer): mixed => {
|
||||
next({username: req.remote_user.name});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,20 +1,25 @@
|
|||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
// @flow
|
||||
|
||||
import type {IAuth, IStorage} from '../../../types';
|
||||
import type {Config} from '@verdaccio/types';
|
||||
|
||||
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';
|
||||
|
||||
const Middleware = require('../web/middleware');
|
||||
const match = Middleware.match;
|
||||
const validateName = Middleware.validate_name;
|
||||
const validatePkg = Middleware.validate_package;
|
||||
const encodeScopePackage = Middleware.encodeScopePackage;
|
||||
|
||||
const whoami = require('./api/whoami');
|
||||
const ping = require('./api/ping');
|
||||
const user = require('./api/user');
|
||||
const distTags = require('./api/dist-tags');
|
||||
const publish = require('./api/publish');
|
||||
const search = require('./api/search');
|
||||
const pkg = require('./api/package');
|
||||
|
||||
module.exports = function(config, auth, storage) {
|
||||
module.exports = function(config: Config, auth: IAuth, storage: IStorage) {
|
||||
/* eslint new-cap:off */
|
||||
const app = express.Router();
|
||||
/* eslint new-cap:off */
|
||||
|
@ -38,23 +43,15 @@ module.exports = function(config, auth, storage) {
|
|||
// app.use(auth.bearer_middleware())
|
||||
app.use(bodyParser.json({strict: false, limit: config.max_body_size || '10mb'}));
|
||||
app.use(Middleware.anti_loop(config));
|
||||
|
||||
// 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);
|
||||
|
||||
search(app, auth, storage);
|
||||
|
||||
user(app, auth);
|
||||
|
||||
distTags(app, auth, storage);
|
||||
|
||||
publish(app, auth, storage, config);
|
||||
|
||||
ping(app);
|
||||
|
||||
return app;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// @flow
|
||||
|
||||
import rimRaf from 'rimraf';
|
||||
import path from 'path';
|
||||
import LocalStorage from '../../src/lib/local-storage';
|
||||
|
|
|
@ -22,6 +22,7 @@ export interface IAuth {
|
|||
secret: string;
|
||||
plugins: Array<any>;
|
||||
aes_encrypt(buf: Buffer): Buffer;
|
||||
basic_middleware(): $NextFunctionVer;
|
||||
add_user(user: string, password: string, cb: Callback): any;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue