From e3a593e142b4df01d60bf088c528a8727e1f6edb Mon Sep 17 00:00:00 2001 From: Remi Kristelijn Date: Thu, 14 Mar 2024 14:15:53 +0100 Subject: [PATCH 1/3] Update admin-redirect.md docs: add serving custom frontend to the default route / --- .../snippets-proxy/admin-redirect.md | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md b/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md index 98ffb2d138..ce6ef13fe9 100644 --- a/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md +++ b/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md @@ -26,3 +26,39 @@ module.exports = (_config, { strapi }) => { strapi.server.routes(redirects); }; ``` + +### Shipping your own pages on / instead of the strapi landing page + +If you do not wish to have the default landing page mounted on `/` you can create a custom middleware using the sample code below to automatically redirect to your custom `index.html` in the `./public` folder. + +```js title="./config/middlewares.js" +module.exports = ({ env }) => [ + // ... + { resolve: '../src/middlewares/root' }, +]; + +``` + +```js title="./src/middlewares/root.js" +const fs = require('fs'); +const path = require('path'); + +module.exports = (_config, { strapi }) => { + const redirects = ['/', '/index.html'].map((routePath) => ({ + method: 'GET', + path: routePath, + handler: (ctx) => { + // Read the index.html file + const filePath = path.resolve(__dirname, '../../public/index.html'); + const fileContents = fs.readFileSync(filePath, 'utf8'); + + // Set the Content-Type header and send the file contents + ctx.type = 'html'; + ctx.body = fileContents; + }, + config: { auth: false }, + })); + + strapi.server.routes(redirects); +}; +``` From ef6cd000d3381fba1d198d39e1bf0e586242e247 Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Fri, 9 Aug 2024 17:40:03 +0200 Subject: [PATCH 2/3] Update docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md Co-authored-by: DMehaffy --- .../docs/dev-docs/deployment/snippets-proxy/admin-redirect.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md b/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md index ce6ef13fe9..0a47dddb01 100644 --- a/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md +++ b/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md @@ -39,7 +39,7 @@ module.exports = ({ env }) => [ ``` -```js title="./src/middlewares/root.js" +```js title="./src/middlewares/admin-redirect.js" const fs = require('fs'); const path = require('path'); From 88c5475ade34e66c3bab34a7f6e18ea1c8e74f5a Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Fri, 9 Aug 2024 17:40:09 +0200 Subject: [PATCH 3/3] Update docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md Co-authored-by: DMehaffy --- .../docs/dev-docs/deployment/snippets-proxy/admin-redirect.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md b/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md index 0a47dddb01..3ab10bf390 100644 --- a/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md +++ b/docusaurus/docs/dev-docs/deployment/snippets-proxy/admin-redirect.md @@ -34,7 +34,7 @@ If you do not wish to have the default landing page mounted on `/` you can creat ```js title="./config/middlewares.js" module.exports = ({ env }) => [ // ... - { resolve: '../src/middlewares/root' }, +"global::admin-redirect", ]; ```