Pierre Noël 57d7d876b7
Fix/#4513/ability to use a sub path behind a proxy (#5833)
* add possibility to use strapi on a non-root base url path

* fix documentation password form

* use server.url and admin.url in config

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* update doc proxy

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* move server.url location in config

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* refacto

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* add possibility to put relative urls

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* allow '/' as an admin url + refacto

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* update yarn.lock

Signed-off-by: Pierre Noël <petersg83@gmail.com>

* refacto

Signed-off-by: Pierre Noël <petersg83@gmail.com>

* Remove default proxy option

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>

* fix github provider

Signed-off-by: Pierre Noël <petersg83@gmail.com>

* fix github login

Signed-off-by: Pierre Noël <petersg83@gmail.com>

* Remove files that should be here

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>

Co-authored-by: Pierre Noël <pierre.noel@strapi.io>
Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com>
2020-05-08 13:50:00 +02:00

32 lines
784 B
JavaScript
Executable File

module.exports = async (ctx, next) => {
const pluginStore = strapi.store({
environment: '',
type: 'plugin',
name: 'documentation',
});
const config = await pluginStore.get({ key: 'config' });
if (!config.restrictedAccess) {
return await next();
}
if (!ctx.session.documentation) {
const querystring = ctx.querystring ? `?${ctx.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
);
if (!isValid) {
ctx.session.documentation = null;
}
// Execute the action.
await next();
};