server.enableFrameworkExt

  • Type: boolean
  • Default: false

By default, when the custom Web Server feature is enabled, the Middleware will use the Modern.js's syntax.

Enabling server.enableFrameworkExt allows the use of syntax extensions from other frameworks.

modern.config.ts
export default defineConfig({
  server: {
    enableFrameworkExt: true,
  },
});

Example

Default usage:

server/index.ts
import { Middleware } from '@modern-js/runtime/server';

export const middleware: Middleware = (ctx, next) => {
  console.log(ctx.request.url);
  next();
};

After enabling it, the Middleware type will be exported from other namespaces, and syntax extensions from frameworks can be used:

server/index.ts
import { SomeType } from '@modern-js/runtime/{namespace}';

export const middleware: SomeType = (...args) => {
  console.log(args[0].url);
  next();
};
NOTE

The above code is pseudocode, and the specific usage needs to refer to the corresponding framework extension.

ON THIS PAGE