I got it to work, meaning; when going to the root http://localhost:1337 you get your custom index.html
// src/middlewares/home.js
const fs = require('fs');
const path = require('path');
/** override index.html
* @see https://docs.strapi.io/dev-docs/deployment/snippets-proxy/admin-redirect#redirecting-landing-page-to-admin-panel
*/
module.exports = (_config, { strapi }) => {
const redirects = ['/', '/index.html'].map((routePath) => ({
method: 'GET',
path: routePath,
// redirects to admin panel
// handler: (ctx) => ctx.redirect('/admin'),
// ship the index.html using koa-send (doesn't work)
handler: (ctx) => {
console.log('🚀 ~ file: home.js ~ line 5 ~ _config', _config);
// 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);
};
// config/middlewares.ts
export default [
'strapi::logger',
'strapi::errors',
'strapi::security',
'strapi::cors',
'strapi::poweredBy',
'strapi::query',
'strapi::body',
'strapi::session',
'strapi::favicon',
{ resolve: '../src/middlewares/home' },
'strapi::public',
];
I would love to the the Typescript version to work, and I was recommended to use koa-send instead