Create middleware transforming responses to make singletype work with strapi-jekyll

System Information
  • Strapi Version: 4.3.4
  • Operating System: Fedora
  • Database: Sqlite
  • Node Version: 16.16.0
  • NPM Version: 8.19.2
  • Yarn Version: 1.22.19

I am trying to write a simple middleware to transport responses to work with jekyll.
Jekyll only uses collections, basically an array, to store data. With the strapi-jekyll plugin only the collections type is working which is mapped to the collection type in jekyll.

One workaround working with older strapi versions to use strapi singletypes was to just add a small middleware wraping single type responses in an array.

I tried to update the workaround to work with the current version of strapi but had no luck so far…
When starting strapi with the middleware strapi is starting up but when browsing http://localhost:1337/admin i get a error.

Anybody a idea how to make this work?

My error when browsing http://localhost:1337/admin

[{"fd":null,"path":"/path/to/my/project/node_modules/@strapi/admin/build/index.html","flags":"r","mode":438,"end":null,"bytesRead":0,"closed":false,"_readableState":{"objectMode":false,"highWaterMark":65536,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":[],"flowing":null,"ended":false,"endEmitted":false,"reading":false,"constructed":false,"sync":true,"needReadable":false,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"errorEmitted":false,"emitClose":true,"autoDestroy":true,"destroyed":false,"errored":null,"closed":false,"closeEmitted":false,"defaultEncoding":"utf8","awaitDrainWriters":null,"multiAwaitDrain":false,"readingMore":false,"dataEmitted":false,"decoder":null,"encoding":null},"_events":{},"_eventsCount":2}]
# ./config/middlewares.js
module.exports = [
  'strapi::errors',
  'strapi::security',
  'strapi::cors',
  {
    name: 'global::single_to_array',
    config: {
      enabled: 'false',
    },
  },
  'strapi::poweredBy',
  'strapi::logger',
  'strapi::query',
  'strapi::body',
  'strapi::session',
  'strapi::favicon',
  'strapi::public',
];
# ./src/middlewares/single_to_array.js
const singleName = "";

module.exports = () => {
  return async (ctx, next) => {
    await next();
    if (ctx.url.startsWith("/" + singleName)) {
        ctx.response.body = [ ctx.response.body ];
    }
  };
};