mirror of
https://github.com/strapi/strapi.git
synced 2025-11-09 14:51:29 +00:00
Server index.html of the admin when nothin else is found on url with /admin
This commit is contained in:
parent
12260bae16
commit
e4e6cba9c8
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Node.js core.
|
// Node.js core.
|
||||||
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const koaStatic = require('koa-static');
|
const koaStatic = require('koa-static');
|
||||||
@ -29,17 +30,10 @@ module.exports = strapi => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Serve /public index page.
|
// Serve /public index page.
|
||||||
strapi.router.get(
|
strapi.router.get('/', ctx => {
|
||||||
'/',
|
ctx.type = 'html';
|
||||||
async (ctx, next) => {
|
ctx.body = fs.createReadStream(path.join(staticDir + '/index.html'));
|
||||||
ctx.url = path.basename(`${ctx.url}/index.html`);
|
});
|
||||||
await next();
|
|
||||||
},
|
|
||||||
koaStatic(staticDir, {
|
|
||||||
maxage: maxAge,
|
|
||||||
defer: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
// Match every route with an extension.
|
// Match every route with an extension.
|
||||||
// The file without extension will not be served.
|
// The file without extension will not be served.
|
||||||
@ -69,50 +63,24 @@ module.exports = strapi => {
|
|||||||
|
|
||||||
const buildDir = path.resolve(strapi.dir, 'build');
|
const buildDir = path.resolve(strapi.dir, 'build');
|
||||||
|
|
||||||
// Serve /admin index page.
|
// Serve admin assets.
|
||||||
strapi.router.get(
|
|
||||||
basename,
|
|
||||||
async (ctx, next) => {
|
|
||||||
ctx.url = 'index.html';
|
|
||||||
await next();
|
|
||||||
},
|
|
||||||
koaStatic(buildDir, {
|
|
||||||
maxage: maxAge,
|
|
||||||
defer: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
// Allow refresh in admin page.
|
|
||||||
strapi.router.get(
|
strapi.router.get(
|
||||||
`${basename}/*`,
|
`${basename}/*`,
|
||||||
async (ctx, next) => {
|
|
||||||
const parse = path.parse(ctx.url);
|
|
||||||
|
|
||||||
if (parse.ext === '') {
|
|
||||||
ctx.url = 'index.html';
|
|
||||||
}
|
|
||||||
|
|
||||||
await next();
|
|
||||||
},
|
|
||||||
koaStatic(buildDir, {
|
|
||||||
maxage: maxAge,
|
|
||||||
defer: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
// Serve admin assets.
|
|
||||||
strapi.router.get(
|
|
||||||
`${basename}/*.*`,
|
|
||||||
async (ctx, next) => {
|
async (ctx, next) => {
|
||||||
ctx.url = path.basename(ctx.url);
|
ctx.url = path.basename(ctx.url);
|
||||||
|
|
||||||
await next();
|
await next();
|
||||||
},
|
},
|
||||||
koaStatic(buildDir, {
|
koaStatic(buildDir, {
|
||||||
|
index: 'index.html',
|
||||||
maxage: maxAge,
|
maxage: maxAge,
|
||||||
defer: true,
|
defer: false,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
strapi.router.get(`${basename}*`, ctx => {
|
||||||
|
ctx.type = 'html';
|
||||||
|
ctx.body = fs.createReadStream(path.join(buildDir + '/index.html'));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user