diff --git a/docs/3.0.0-alpha.x/guides/authentication.md b/docs/3.0.0-alpha.x/guides/authentication.md index 9cd651e249..d756eff32e 100644 --- a/docs/3.0.0-alpha.x/guides/authentication.md +++ b/docs/3.0.0-alpha.x/guides/authentication.md @@ -139,8 +139,7 @@ import axios from 'axios'; axios .post('http://localhost:1337/auth/forgot-password', { email: 'user@strapi.io', - url: - 'http:/localhost:1337/admin/plugins/users-permissions/auth/reset-password', + url: 'http:/localhost:1337/admin/plugins/users-permissions/auth/reset-password', }) .then(response => { // Handle success. diff --git a/docs/3.0.0-beta.x/concepts/configurations.md b/docs/3.0.0-beta.x/concepts/configurations.md index d69cb4d1e2..2da9b5ea42 100644 --- a/docs/3.0.0-beta.x/concepts/configurations.md +++ b/docs/3.0.0-beta.x/concepts/configurations.md @@ -173,16 +173,12 @@ module.exports = ({ env }) => ({ | `host` | Host name | string | `localhost` | | `port` | Port on which the server should be running. | integer | `1337` | | `emitErrors` | Enable errors to be emitted to `koa` when they happen in order to attach custom logic or use error reporting services. | boolean | | -| `proxy` | Proxy configuration | Object | | -| `proxy.enabled` | Enable proxy support such as Apache or Nginx. | boolean | `false` | -| `proxy.ssl` | Enable proxy SSL support. | boolean | | -| `proxy.host` | Host name your proxy service uses for Strapi. | string | | -| `proxy.port` | Port that your proxy service accepts connections on. | integer | | +| `url` | Url of the server. Enable proxy support such as Apache or Nginx, example: `https://mywebsite.com/api`. Default value: `http://${host}:${port}`. | string | | | `cron` | Cron configuration (powered by [`node-schedule`](https://github.com/node-schedule/node-schedule)) | Object | | | `cron.enabled` | Enable or disable CRON tasks to schedule jobs at specific dates. | boolean | `false` | | `admin` | Admin panel configuration | Object | | +| `admin.url` | Url of your admin panel. Default value: `/admin`. Note: If the url is relative, it will be concatenated with `url`. | string | `/admin` | | `admin.autoOpen` | Enable or disabled administration opening on start. | boolean | `true` | -| `admin.path` | Allow to change the URL to access the admin panel. | string | `/admin` | | `admin.watchIgnoreFiles` | Add custom files that should not be watched during development. See more [here](https://github.com/paulmillr/chokidar#path-filtering) (property `ignored`). | Array(string) | `[]`. | | `admin.build` | Admin panel build configuration | Object | | | `admin.build.backend` | URL that the admin panel and plugins will request | string | | diff --git a/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.17-to-beta.18.md b/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.17-to-beta.18.md index d411ba5030..57a989584b 100644 --- a/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.17-to-beta.18.md +++ b/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.17-to-beta.18.md @@ -2,7 +2,7 @@ Upgrading your Strapi application to `v3.0.0-beta.18`. -**Make sure your server is not running until then end of the migration** +**Make sure your server is not running until the end of the migration** ## Upgrading your dependencies diff --git a/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.18-to-beta.19.md b/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.18-to-beta.19.md index 7a04141803..c76ee7dd14 100644 --- a/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.18-to-beta.19.md +++ b/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.18-to-beta.19.md @@ -2,7 +2,7 @@ Upgrading your Strapi application to `v3.0.0-beta.19`. -**Make sure your server is not running until then end of the migration** +**Make sure your server is not running until the end of the migration** ## Upgrading your dependencies diff --git a/packages/strapi-connector-bookshelf/lib/knex.js b/packages/strapi-connector-bookshelf/lib/knex.js index 70ea60696a..8f52f39a7a 100644 --- a/packages/strapi-connector-bookshelf/lib/knex.js +++ b/packages/strapi-connector-bookshelf/lib/knex.js @@ -76,13 +76,9 @@ module.exports = strapi => { try { client = require(connection.settings.client); } catch (err) { + strapi.log.error('The client `' + connection.settings.client + '` is not installed.'); strapi.log.error( - 'The client `' + connection.settings.client + '` is not installed.' - ); - strapi.log.error( - 'You can install it with `$ npm install ' + - connection.settings.client + - ' --save`.' + 'You can install it with `$ npm install ' + connection.settings.client + ' --save`.' ); strapi.stop(); } @@ -92,9 +88,7 @@ module.exports = strapi => { client: connection.settings.client, connection: { host: _.get(connection.settings, 'host'), - user: - _.get(connection.settings, 'username') || - _.get(connection.settings, 'user'), + user: _.get(connection.settings, 'username') || _.get(connection.settings, 'user'), password: _.get(connection.settings, 'password'), database: _.get(connection.settings, 'database'), charset: _.get(connection.settings, 'charset'), @@ -106,10 +100,7 @@ module.exports = strapi => { filename: _.get(connection.settings, 'filename', '.tmp/data.db'), }, debug: _.get(connection.options, 'debug', false), - acquireConnectionTimeout: _.get( - connection.options, - 'acquireConnectionTimeout' - ), + acquireConnectionTimeout: _.get(connection.options, 'acquireConnectionTimeout'), migrations: _.get(connection.options, 'migrations'), useNullAsDefault: _.get(connection.options, 'useNullAsDefault'), }, @@ -121,26 +112,10 @@ module.exports = strapi => { options.pool = { min: _.get(connection.options, 'pool.min', 0), max: _.get(connection.options, 'pool.max', 10), - acquireTimeoutMillis: _.get( - connection.options, - 'pool.acquireTimeoutMillis', - 2000 - ), - createTimeoutMillis: _.get( - connection.options, - 'pool.createTimeoutMillis', - 2000 - ), - idleTimeoutMillis: _.get( - connection.options, - 'pool.idleTimeoutMillis', - 30000 - ), - reapIntervalMillis: _.get( - connection.options, - 'pool.reapIntervalMillis', - 1000 - ), + acquireTimeoutMillis: _.get(connection.options, 'pool.acquireTimeoutMillis', 2000), + createTimeoutMillis: _.get(connection.options, 'pool.createTimeoutMillis', 2000), + idleTimeoutMillis: _.get(connection.options, 'pool.idleTimeoutMillis', 30000), + reapIntervalMillis: _.get(connection.options, 'pool.reapIntervalMillis', 1000), createRetryIntervalMillis: _.get( connection.options, 'pool.createRetryIntervalMillis', @@ -151,9 +126,7 @@ module.exports = strapi => { // Resolve path to the directory containing the database file. const fileDirectory = options.connection.filename - ? path.dirname( - path.resolve(strapi.config.appPath, options.connection.filename) - ) + ? path.dirname(path.resolve(strapi.config.appPath, options.connection.filename)) : ''; switch (options.client) { @@ -180,12 +153,9 @@ module.exports = strapi => { options.pool = { ...options.pool, afterCreate: (conn, cb) => { - conn.query( - `SET SESSION SCHEMA '${options.connection.schema}';`, - err => { - cb(err, conn); - } - ); + conn.query(`SET SESSION SCHEMA '${options.connection.schema}';`, err => { + cb(err, conn); + }); }, }; } else { @@ -227,9 +197,7 @@ module.exports = strapi => { } catch (err) { strapi.log.error('Impossible to use the `' + name + '` connection...'); strapi.log.warn( - 'Be sure that your client `' + - name + - '` are in the same node_modules directory' + 'Be sure that your client `' + name + '` are in the same node_modules directory' ); strapi.log.error(err); strapi.stop(); diff --git a/packages/strapi-plugin-documentation/config/policies/index.js b/packages/strapi-plugin-documentation/config/policies/index.js index 0b03c5f564..945239ee2a 100755 --- a/packages/strapi-plugin-documentation/config/policies/index.js +++ b/packages/strapi-plugin-documentation/config/policies/index.js @@ -13,9 +13,14 @@ module.exports = async (ctx, next) => { if (!ctx.session.documentation) { const querystring = ctx.querystring ? `?${ctx.querystring}` : ''; - return ctx.redirect(`${strapi.plugins.documentation.config['x-strapi-config'].path}/login${querystring}`); + return ctx.redirect( + `${strapi.config.server.url}${strapi.plugins.documentation.config['x-strapi-config'].path}/login${querystring}` + ); } - const isValid = strapi.plugins['users-permissions'].services.user.validatePassword(ctx.session.documentation, config.password); + const isValid = strapi.plugins['users-permissions'].services.user.validatePassword( + ctx.session.documentation, + config.password + ); if (!isValid) { ctx.session.documentation = null; diff --git a/packages/strapi-plugin-documentation/controllers/Documentation.js b/packages/strapi-plugin-documentation/controllers/Documentation.js index 30f1241f81..1d2781c9f5 100755 --- a/packages/strapi-plugin-documentation/controllers/Documentation.js +++ b/packages/strapi-plugin-documentation/controllers/Documentation.js @@ -18,11 +18,6 @@ const koaStatic = require('koa-static'); module.exports = { getInfos: async ctx => { try { - const prefix = _.get( - strapi.plugins, - ['documentation', 'config', 'x-strapi-config', 'path'], - '/documentation' - ); const service = strapi.plugins.documentation.services.documentation; const docVersions = service.retrieveDocumentationVersions(); const form = await service.retrieveFrontForm(); @@ -30,7 +25,7 @@ module.exports = { ctx.send({ docVersions, currentVersion: service.getDocumentationVersion(), - prefix: `/${prefix}`.replace('//', '/'), + prefix: strapi.plugins.documentation.config['x-strapi-config'].path, form, }); } catch (err) { @@ -39,15 +34,7 @@ module.exports = { }, async index(ctx, next) { - // Read layout file. - try { - const layout = fs.readFileSync( - path.resolve(__dirname, '..', 'public', 'index.html'), - 'utf8' - ); - const $ = cheerio.load(layout); - /** * We don't expose the specs using koa-static or something else due to security reasons. * That's why, we need to read the file localy and send the specs through it when we serve the Swagger UI. @@ -68,39 +55,16 @@ module.exports = { try { const documentation = fs.readFileSync(openAPISpecsPath, 'utf8'); - - // Remove previous Swagger configuration. - $('.custom-swagger-ui').remove(); - // Set new Swagger configuration - $('body').append(` - - `); + const layout = fs.readFileSync( + path.resolve(__dirname, '..', 'public', 'index.html'), + 'utf8' + ); + const filledLayout = _.template(layout)({ + backendUrl: strapi.config.server.url, + spec: JSON.stringify(JSON.parse(documentation)), + }); try { - // Write the layout with the new Swagger configuration. - // fs.writeFileSync(layoutPath, $.html()); const layoutPath = path.resolve( strapi.config.appPath, 'extensions', @@ -109,7 +73,7 @@ module.exports = { 'index.html' ); await fs.ensureFile(layoutPath); - await fs.writeFile(layoutPath, $.html()); + await fs.writeFile(layoutPath, filledLayout); // Serve the file. ctx.url = path.basename(`${ctx.url}/index.html`); @@ -140,15 +104,12 @@ module.exports = { const { error } = ctx.query; try { - const layout = fs.readFileSync( - path.join(__dirname, '..', 'public', 'login.html') - ); - const $ = cheerio.load(layout); + const layout = fs.readFileSync(path.join(__dirname, '..', 'public', 'login.html')); + const filledLayout = _.template(layout)({ + actionUrl: `${strapi.config.server.url}${strapi.plugins.documentation.config['x-strapi-config'].path}/login`, + }); + const $ = cheerio.load(filledLayout); - $('form').attr( - 'action', - `${strapi.plugins.documentation.config['x-strapi-config'].path}/login` - ); $('.error').text(_.isEmpty(error) ? '' : 'Wrong password...'); try { @@ -197,9 +158,10 @@ module.exports = { }) .get(); - const isValid = strapi.plugins[ - 'users-permissions' - ].services.user.validatePassword(password, storedPassword); + const isValid = strapi.plugins['users-permissions'].services.user.validatePassword( + password, + storedPassword + ); let querystring = '?error=password'; if (isValid) { @@ -208,17 +170,13 @@ module.exports = { } ctx.redirect( - `${ - strapi.plugins.documentation.config['x-strapi-config'].path - }${querystring}` + `${strapi.config.server.url}${strapi.plugins.documentation.config['x-strapi-config'].path}${querystring}` ); }, regenerateDoc: async ctx => { const service = strapi.plugins.documentation.services.documentation; - const documentationVersions = service - .retrieveDocumentationVersions() - .map(el => el.version); + const documentationVersions = service.retrieveDocumentationVersions().map(el => el.version); const { request: { body: { version }, @@ -254,10 +212,7 @@ module.exports = { ); ctx.send({ ok: true }); } catch (err) { - ctx.badRequest( - null, - admin ? 'documentation.error.regenerateDoc' : 'An error occured' - ); + ctx.badRequest(null, admin ? 'documentation.error.regenerateDoc' : 'An error occured'); } finally { strapi.reload.isWatching = true; } @@ -266,9 +221,7 @@ module.exports = { deleteDoc: async ctx => { strapi.reload.isWatching = false; const service = strapi.plugins.documentation.services.documentation; - const documentationVersions = service - .retrieveDocumentationVersions() - .map(el => el.version); + const documentationVersions = service.retrieveDocumentationVersions().map(el => el.version); const { request: { params: { version }, @@ -318,14 +271,11 @@ module.exports = { if (restrictedAccess && _.isEmpty(password)) { return ctx.badRequest( null, - admin - ? 'users-permissions.Auth.form.error.password.provide' - : 'Please provide a password' + admin ? 'users-permissions.Auth.form.error.password.provide' : 'Please provide a password' ); } - const isNewPassword = - !_.isEmpty(password) && password !== prevConfig.password; + const isNewPassword = !_.isEmpty(password) && password !== prevConfig.password; if (isNewPassword && usersPermService.user.isHashed(password)) { // Throw an error if the password selected by the user diff --git a/packages/strapi-plugin-documentation/middlewares/documentation/index.js b/packages/strapi-plugin-documentation/middlewares/documentation/index.js index f82b6f7317..c5ad7553e9 100755 --- a/packages/strapi-plugin-documentation/middlewares/documentation/index.js +++ b/packages/strapi-plugin-documentation/middlewares/documentation/index.js @@ -18,9 +18,7 @@ module.exports = strapi => { beforeInitialize() { strapi.config.middleware.load.before.push('documentation'); - initialRoutes.push( - ..._.cloneDeep(strapi.plugins.documentation.config.routes) - ); + initialRoutes.push(..._.cloneDeep(strapi.plugins.documentation.config.routes)); }, initialize() { @@ -31,22 +29,12 @@ module.exports = strapi => { return route; } - if ( - route.handler === 'Documentation.index' || - route.path === '/login' - ) { + if (route.handler === 'Documentation.index' || route.path === '/login') { route.config.policies = initialRoutes[index].config.policies; } // Set prefix to empty to be able to customise it. - if ( - _.get(strapi.plugins, [ - 'documentation', - 'config', - 'x-strapi-config', - 'path', - ]) - ) { + if (_.get(strapi.plugins, ['documentation', 'config', 'x-strapi-config', 'path'])) { route.config.prefix = ''; route.path = `/${strapi.plugins.documentation.config['x-strapi-config'].path}${route.path}`.replace( '//', diff --git a/packages/strapi-plugin-documentation/public/index.html b/packages/strapi-plugin-documentation/public/index.html index ac773b2472..eab31e9887 100755 --- a/packages/strapi-plugin-documentation/public/index.html +++ b/packages/strapi-plugin-documentation/public/index.html @@ -1,9 +1,9 @@