mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
refactor: middleware plugins
add es6 transpiled use case
This commit is contained in:
parent
d5a29f72b5
commit
a1a70c973f
6 changed files with 82 additions and 14 deletions
|
@ -258,7 +258,7 @@ class Auth {
|
|||
const scheme = parts[0];
|
||||
if (scheme.toUpperCase() === 'BASIC') {
|
||||
credentials = new Buffer(parts[1], 'base64').toString();
|
||||
this.logger.warn('basic authentication is deprecated, please use JWT instead');
|
||||
this.logger.info('basic authentication is deprecated, please use JWT instead');
|
||||
return credentials;
|
||||
} else if (scheme.toUpperCase() === 'BEARER') {
|
||||
const token = new Buffer(parts[1], 'base64');
|
||||
|
|
53
test/functional/fixtures/plugins/middlewares.es6.js
Normal file
53
test/functional/fixtures/plugins/middlewares.es6.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Original plugin in ES6
|
||||
*
|
||||
* class PluginES6 {
|
||||
|
||||
constructor (config, stuff) {
|
||||
this._config = config;
|
||||
}
|
||||
|
||||
register_middlewares(app, auth, storage) {
|
||||
const {message} = this._config;
|
||||
|
||||
app.get('/test/route/es6', function (req, res, next) {
|
||||
res.status(200);
|
||||
|
||||
return next({ok: message})
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default PluginES6;
|
||||
|
||||
*/
|
||||
|
||||
// this file has been transpiled with babel.js
|
||||
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
class PluginES6 {
|
||||
|
||||
constructor(config, stuff) {
|
||||
this._config = config;
|
||||
}
|
||||
|
||||
register_middlewares(app, auth, storage) {
|
||||
const message = this._config.message;
|
||||
|
||||
|
||||
app.get('/test/route/es6', function (req, res, next) {
|
||||
res.status(200);
|
||||
|
||||
return next({ ok: message });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = PluginES6;
|
||||
|
|
@ -1,17 +1,19 @@
|
|||
|
||||
module.exports = Plugin
|
||||
|
||||
function Plugin(config, stuff) {
|
||||
var self = Object.create(Plugin.prototype)
|
||||
self._config = config
|
||||
return self
|
||||
const self = Object.create(Plugin.prototype);
|
||||
|
||||
self._config = config;
|
||||
return self;
|
||||
}
|
||||
|
||||
Plugin.prototype.register_middlewares = function (app, auth, storage) {
|
||||
var message = this._config.message
|
||||
|
||||
const {message} = this._config;
|
||||
app.get('/test/route', function (req, res, next) {
|
||||
res.status(200)
|
||||
res.status(200);
|
||||
|
||||
return next({ ok: message })
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
module.exports = Plugin;
|
||||
|
|
|
@ -25,6 +25,7 @@ import racycrash from './sanity/racycrash';
|
|||
import security from './sanity/security';
|
||||
import race from './performance/race';
|
||||
import pluginsAuth from './plugins/auth';
|
||||
import middleware from './plugins/middleware';
|
||||
import upLinkCache from './uplinks/cache';
|
||||
|
||||
describe('functional test verdaccio', function() {
|
||||
|
@ -45,6 +46,7 @@ describe('functional test verdaccio', function() {
|
|||
preserveTags(server1, server2, app);
|
||||
readme(server1, server2);
|
||||
nullstorage(server1, server2);
|
||||
middleware(server2);
|
||||
race(server1);
|
||||
racycrash(server1, app);
|
||||
packageScoped(server1, server2);
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
module.exports = function () {
|
||||
const server2 = process.server2;
|
||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
||||
|
||||
describe('middlewares', () => {
|
||||
test('should serve the registered route', () => {
|
||||
export default function (server2) {
|
||||
describe('test plugin middlewares', () => {
|
||||
test('should serve the registered route ES5', () => {
|
||||
return server2.request({
|
||||
uri: '/test/route',
|
||||
method: 'GET'
|
||||
})
|
||||
.status(200)
|
||||
.status(HTTP_STATUS.OK)
|
||||
.body_ok('this is a custom route')
|
||||
})
|
||||
|
||||
test('should serve the registered route ES6', () => {
|
||||
return server2.request({
|
||||
uri: '/test/route/es6',
|
||||
method: 'GET'
|
||||
})
|
||||
.status(HTTP_STATUS.OK)
|
||||
.body_ok('this is a custom route es6')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ web:
|
|||
middlewares:
|
||||
../fixtures/plugins/middlewares:
|
||||
message: this is a custom route
|
||||
../fixtures/plugins/middlewares.es6:
|
||||
message: this is a custom route es6
|
||||
|
||||
max_users: 3
|
||||
|
||||
|
|
Loading…
Reference in a new issue