diff --git a/docs/docker.md b/docs/docker.md
index d72755dc2..e13dce2c5 100644
--- a/docs/docker.md
+++ b/docs/docker.md
@@ -55,13 +55,14 @@ The above line will pull the latest prebuilt image from dockerhub, if you haven'
If you have [build an image locally](#build-your-own-docker-image) use `verdaccio` as the last argument.
-You can use `-v` to mount `conf` and `storage` to the hosts filesystem:
+You can use `-v` to bind mount `conf` and `storage` to the hosts filesystem:
```bash
V_PATH=/path/for/verdaccio; docker run -it --rm --name verdaccio -p 4873:4873 \
-v $V_PATH/conf:/verdaccio/conf \
-v $V_PATH/storage:/verdaccio/storage \
verdaccio/verdaccio
```
+>Note: Verdaccio runs as a non-root user (uid=101, gid=101) inside the container, if you use bind mount to override default, you need to make sure the mount directory is assigned to the right user. In above example, you need to run `sudo chown -R 101:101 /opt/verdaccio` otherwise you will get permission errors at runtime. [Use docker volume](https://docs.docker.com/storage/volumes/) is recommended over using bind mount.
### Docker and custom port configuration
Any `host:port` configured in `conf/config.yaml` under `listen` is currently ignored when using docker.
diff --git a/package.json b/package.json
index 3b15ef7f7..5c3d29051 100644
--- a/package.json
+++ b/package.json
@@ -27,6 +27,7 @@
"compression": "1.7.2",
"cookies": "0.7.1",
"cors": "2.8.4",
+ "date-fns": "1.29.0",
"express": "4.16.2",
"global": "4.3.2",
"handlebars": "4.0.11",
@@ -51,7 +52,6 @@
"@commitlint/config-conventional": "6.1.3",
"@commitlint/travis-cli": "6.1.3",
"@verdaccio/types": "2.0.2",
- "axios": "0.18.0",
"babel-cli": "6.26.0",
"babel-core": "6.26.0",
"babel-eslint": "8.2.2",
@@ -126,10 +126,11 @@
"supertest": "3.0.0",
"url-loader": "0.6.2",
"verdaccio-auth-memory": "0.0.4",
- "verdaccio-memory": "0.0.3",
+ "verdaccio-memory": "0.0.6",
"webpack": "3.10.0",
"webpack-dev-server": "2.11.1",
- "webpack-merge": "4.1.2"
+ "webpack-merge": "4.1.2",
+ "whatwg-fetch": "2.0.3"
},
"keywords": [
"private",
@@ -147,10 +148,10 @@
"prepublish": "in-publish && npm run build:webui && npm run code:build || not-in-publish",
"flow": "flow",
"pretest": "npm run code:build",
- "test": "cross-env NODE_ENV=test BABEL_ENV=test jest --maxWorkers 2",
+ "test": "cross-env NODE_ENV=test BABEL_ENV=test TZ=UTC jest --maxWorkers 2",
"test:e2e": "cross-env BABEL_ENV=registry jest --config ./jest.e2e.config.js --maxWorkers 2",
"test:all": "npm run test && npm run test:e2e",
- "test:unit": "cross-env NODE_ENV=test BABEL_ENV=test jest '(/test/unit.*\\.spec|/test/webui/.*\\.spec)\\.js' --maxWorkers 2",
+ "test:unit": "cross-env NODE_ENV=test BABEL_ENV=test TZ=UTC jest '(/test/unit.*\\.spec|/test/webui/.*\\.spec)\\.js' --maxWorkers 2",
"test:func": "cross-env NODE_ENV=test BABEL_ENV=test jest '(/test/functional.*\\.func)\\.js' --maxWorkers 2",
"pre:ci": "npm run lint && npm run build:webui",
"commitmsg": "commitlint -e $GIT_PARAMS",
diff --git a/src/api/web/endpoint/user.js b/src/api/web/endpoint/user.js
index bf459306d..2c57f6b75 100644
--- a/src/api/web/endpoint/user.js
+++ b/src/api/web/endpoint/user.js
@@ -4,7 +4,6 @@ import HTTPError from 'http-errors';
import type {Config} from '@verdaccio/types';
import type {Router} from 'express';
import type {IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer} from '../../../../types';
-// import {combineBaseUrl, getWebProtocol} from '../../../lib/utils';
function addUserAuthApi(route: Router, auth: IAuth, config: Config) {
route.post('/login', function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
@@ -21,14 +20,6 @@ function addUserAuthApi(route: Router, auth: IAuth, config: Config) {
}
});
});
-
- // FIXME: this will be re-implemented
- // route.post('/-/logout', function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
- // const base = combineBaseUrl(getWebProtocol(req), req.get('host'), config.url_prefix);
-
- // res.cookies.set('token', '');
- // res.redirect(base);
- // });
}
export default addUserAuthApi;
diff --git a/src/lib/auth.js b/src/lib/auth.js
index 622d0af4c..1209ac27e 100644
--- a/src/lib/auth.js
+++ b/src/lib/auth.js
@@ -308,11 +308,12 @@ class Auth {
/**
* JWT middleware for WebUI
- * @return {Function}
*/
jwtMiddleware() {
return (req: $RequestExtend, res: $Response, _next: NextFunction) => {
- if (req.remote_user !== null && req.remote_user.name !== undefined) return _next();
+ if (req.remote_user !== null && req.remote_user.name !== undefined) {
+ return _next();
+ }
req.pause();
const next = function(_err) {
@@ -320,18 +321,22 @@ class Auth {
return _next();
};
- req.remote_user = buildAnonymousUser();
-
- let token = (req.headers.authorization || '').replace('Bearer ', '');
- if (!token) return next();
+ const token = (req.headers.authorization || '').replace('Bearer ', '');
+ if (!token) {
+ return next();
+ }
let decoded;
try {
decoded = this.decode_token(token);
- } catch (err) {/**/}
+ } catch (err) {
+ // FIXME: intended behaviour, do we want it?
+ }
if (decoded) {
req.remote_user = authenticatedUser(decoded.user, decoded.group);
+ } else {
+ req.remote_user = buildAnonymousUser();
}
next();
diff --git a/src/webui/src/components/Header/index.js b/src/webui/src/components/Header/index.js
index 397fed3d9..7aec24afa 100644
--- a/src/webui/src/components/Header/index.js
+++ b/src/webui/src/components/Header/index.js
@@ -1,17 +1,16 @@
import React from 'react';
import {Button, Dialog, Input, Alert} from 'element-react';
import isString from 'lodash/isString';
-import get from 'lodash/get';
import isNumber from 'lodash/isNumber';
import {Link} from 'react-router-dom';
import API from '../../../utils/api';
import storage from '../../../utils/storage';
-
+import {getRegistryURL} from '../../../utils/url';
import classes from './header.scss';
import './logo.png';
-import {getRegistryURL} from '../../../utils/url';
+
export default class Header extends React.Component {
state = {
@@ -43,10 +42,8 @@ export default class Header extends React.Component {
}
componentWillMount() {
- API.get('logo')
- .then((response) => {
- this.setState({logo: response.data});
- })
+ API.request('logo')
+ .then((response) => response.text().then((logo) => this.setState({logo})))
.catch((error) => {
throw new Error(error);
});
@@ -62,26 +59,27 @@ export default class Header extends React.Component {
}
try {
- let resp = await API.post(`login`, {
- data: {
- username: this.state.username,
- password: this.state.password
+ const credentials = {
+ username: this.state.username,
+ password: this.state.password
+ };
+ let resp = await API.request(`login`, 'POST', {
+ body: JSON.stringify(credentials),
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json'
}
- });
+ }).then((response) => response.json());
- storage.setItem('token', resp.data.token);
- storage.setItem('username', resp.data.username);
+ storage.setItem('token', resp.token);
+ storage.setItem('username', resp.username);
location.reload();
} catch (e) {
const errorObj = {
title: 'Unable to login',
type: 'error'
};
- if (get(e, 'response.status', 0) === 401) {
- errorObj.description = e.response.data.error;
- } else {
- errorObj.description = e.message;
- }
+ errorObj.description = e.message;
this.setState({loginError: errorObj});
}
}
diff --git a/src/webui/src/components/PackageSidebar/index.jsx b/src/webui/src/components/PackageSidebar/index.jsx
index b4830a83b..a95f602bc 100644
--- a/src/webui/src/components/PackageSidebar/index.jsx
+++ b/src/webui/src/components/PackageSidebar/index.jsx
@@ -32,7 +32,9 @@ export default class PackageSidebar extends React.Component {
let packageMeta;
try {
- packageMeta = (await API.get(`sidebar/${packageName}`)).data;
+ packageMeta = await API.request(`sidebar/${packageName}`, 'GET').then(function(response) {
+ return response.json();
+ });
} catch (err) {
this.setState({
failed: true
diff --git a/src/webui/src/components/PackageSidebar/modules/LastSync/index.jsx b/src/webui/src/components/PackageSidebar/modules/LastSync/index.jsx
index fb768e1fd..b0baee60e 100644
--- a/src/webui/src/components/PackageSidebar/modules/LastSync/index.jsx
+++ b/src/webui/src/components/PackageSidebar/modules/LastSync/index.jsx
@@ -1,9 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
+import format from 'date-fns/format';
import Module from '../../Module';
-import datetime from '../../../../../utils/datetime';
import classes from './style.scss';
+const TIMEFORMAT = 'YYYY/MM/DD, HH:mm:ss';
+
export default class LastSync extends React.Component {
static propTypes = {
packageMeta: PropTypes.object.isRequired
@@ -19,15 +21,15 @@ export default class LastSync extends React.Component {
}
});
- return lastUpdate ? datetime(lastUpdate) : '';
+ const time = format(new Date(lastUpdate), TIMEFORMAT);
+
+ return lastUpdate ? time : '';
}
get recentReleases() {
let recentReleases = Object.keys(this.props.packageMeta.time).map((version) => {
- return {
- version,
- time: datetime(this.props.packageMeta.time[version])
- };
+ const time = format(new Date(this.props.packageMeta.time[version]), TIMEFORMAT);
+ return {version, time};
});
return recentReleases.slice(recentReleases.length - 3, recentReleases.length).reverse();
diff --git a/src/webui/src/modules/detail/index.jsx b/src/webui/src/modules/detail/index.jsx
index 744b24ce8..acd93be16 100644
--- a/src/webui/src/modules/detail/index.jsx
+++ b/src/webui/src/modules/detail/index.jsx
@@ -47,9 +47,9 @@ export default class Detail extends React.Component {
});
try {
- const resp = await API.get(`package/readme/${packageName}`);
+ const resp = await API.request(`package/readme/${packageName}`, 'GET').then((response) => response.text());
this.setState({
- readMe: resp.data
+ readMe: resp
});
} catch (err) {
this.setState({
diff --git a/src/webui/src/modules/home/index.js b/src/webui/src/modules/home/index.js
index d055cf623..8fcc17083 100644
--- a/src/webui/src/modules/home/index.js
+++ b/src/webui/src/modules/home/index.js
@@ -52,11 +52,11 @@ export default class Home extends React.Component {
async loadPackages() {
try {
- this.req = await API.get('packages');
+ this.req = await API.request('packages', 'GET').then((response) => response.json());
if (this.state.query === '') {
this.setState({
- packages: this.req.data,
+ packages: this.req,
loading: false
});
}
@@ -71,12 +71,12 @@ export default class Home extends React.Component {
async searchPackage(query) {
try {
- this.req = await API.get(`/search/${query}`);
+ this.req = await API.request(`/search/${query}`, 'GET').then((response) => response.json());
// Implement cancel feature later
if (this.state.query === query) {
this.setState({
- packages: this.req.data,
+ packages: this.req,
fistTime: false,
loading: false
});
diff --git a/src/webui/utils/api.js b/src/webui/utils/api.js
index 7995bc4d2..084738dfd 100644
--- a/src/webui/utils/api.js
+++ b/src/webui/utils/api.js
@@ -1,34 +1,34 @@
import storage from './storage';
-import axios from 'axios';
class API {
- constructor() {
- ['get', 'delete', 'post', 'put', 'patch'].map((method) => {
- this[method] = (url, options = {}) => {
- if (!window.VERDACCIO_API_URL) {
- throw new Error('VERDACCIO_API_URL is not defined!');
+ request(url, method = 'GET', options = {}) {
+ if (!window.VERDACCIO_API_URL) {
+ throw new Error('VERDACCIO_API_URL is not defined!');
+ }
+
+ const token = storage.getItem('token');
+ if (token) {
+ if (!options.headers) options.headers = {};
+
+ options.headers.authorization = token;
+ }
+
+ if (!['http://', 'https://', '//'].some((prefix) => url.startsWith(prefix))) {
+ url = window.VERDACCIO_API_URL + url;
+ }
+
+ function handleErrors(response) {
+ if (!response.ok) {
+ throw Error(response.statusText);
}
+ return response;
+ }
- const token = storage.getItem('token');
- if (token) {
- if (!options.headers) options.headers = {};
-
- options.headers.authorization = token;
- }
-
- if (!['http://', 'https://', '//'].some((prefix) => url.startsWith(prefix))) {
- url = window.VERDACCIO_API_URL + url;
- }
-
- return axios.request({
- method,
- url,
- ...options
- });
- };
- });
- }
+ return fetch(url, {
+ method,
+ ...options
+ }).then(handleErrors);
+ }
}
-
export default new API();
diff --git a/src/webui/utils/datetime.js b/src/webui/utils/datetime.js
deleted file mode 100644
index 84d8cb19c..000000000
--- a/src/webui/utils/datetime.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * Date time in LocaleString
- * @param {string} input
- * @returns {string}
- */
-export default function datetime(input) {
- const date = new Date(input);
- return date.toLocaleString('en-GB', {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: 'numeric',
- minute: 'numeric',
- hour12: true
- });
-}
diff --git a/test/e2e/config/config-protected-e2e.yaml b/test/e2e/config/config-protected-e2e.yaml
index eac094bdb..bfd346c73 100644
--- a/test/e2e/config/config-protected-e2e.yaml
+++ b/test/e2e/config/config-protected-e2e.yaml
@@ -7,7 +7,7 @@ web:
store:
memory:
- cache: true
+ limit: 10
auth:
auth-memory:
diff --git a/test/e2e/config/config-scoped-e2e.yaml b/test/e2e/config/config-scoped-e2e.yaml
index 22c12449a..3ac364b15 100644
--- a/test/e2e/config/config-scoped-e2e.yaml
+++ b/test/e2e/config/config-scoped-e2e.yaml
@@ -7,7 +7,7 @@ web:
store:
memory:
- cache: true
+ limit: 10
auth:
auth-memory:
diff --git a/test/unit/up-storage.spec.js b/test/unit/up-storage.spec.js
index 035079d36..8df37d4eb 100644
--- a/test/unit/up-storage.spec.js
+++ b/test/unit/up-storage.spec.js
@@ -12,6 +12,7 @@ import type {IProxy} from '../../types';
setup([]);
describe('UpStorge', () => {
+ jest.setTimeout(10000);
const uplinkDefault = {
url: 'https://registry.npmjs.org/'
diff --git a/test/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap b/test/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap
index 706e2c3bc..50f71ce7b 100644
--- a/test/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap
+++ b/test/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`