backend/middlewares/next-proxy/index.js (view raw)
1const proxy = require('koa-proxy');
2
3module.exports = strapi => ({
4 async initialize() {
5 const {host = '', conf = {}} = strapi.config.middleware.settings[
6 'next-proxy'
7 ];
8
9 strapi.router.get('/', proxy({host, ...conf}));
10
11 strapi.app.use(async (ctx, next) => {
12 await next();
13
14 if (ctx.response.status === 404) {
15 await proxy({host, ...conf})(ctx);
16 }
17 });
18 },
19});