2017-12-01 14:04:01 -05:00
|
|
|
/**
|
|
|
|
* API Mocks for WebUI
|
|
|
|
*/
|
|
|
|
import logo from '../store/logo';
|
|
|
|
import login from '../store/login';
|
2017-12-19 23:10:53 -05:00
|
|
|
import { packageMeta } from '../store/packageMeta';
|
2017-12-01 14:04:01 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register mock api endpoints
|
|
|
|
* @param {string} endpoint
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
|
|
|
const register = (method = 'get', endpoint, config = {}) => {
|
|
|
|
|
|
|
|
if (endpoint === 'login' && method === 'post') {
|
|
|
|
return login(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endpoint === 'logo' && method === 'get') {
|
|
|
|
return logo();
|
|
|
|
}
|
|
|
|
|
2017-12-19 23:10:53 -05:00
|
|
|
if (endpoint === 'sidebar/verdaccio' && method === 'get') {
|
|
|
|
return Promise.resolve({ data: packageMeta });
|
|
|
|
}
|
|
|
|
|
2017-12-01 14:04:01 -05:00
|
|
|
return Promise.reject({ status: 404, data: 'Not found' });
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind API methods
|
|
|
|
*/
|
|
|
|
const API = ['get', 'post'].reduce((api, method) => {
|
|
|
|
api[method] = register.bind(null, method);
|
|
|
|
return api;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
export default API;
|