@leafage/server
Version:
The React Server Side Render Framework
36 lines (33 loc) • 1.2 kB
JavaScript
/**
* @leafage/server v1.3.2
*
* Copyright (c) Leafage.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
import { typeof as _typeof } from '../_virtual/_rollupPluginBabelHelpers.js';
import path from 'node:path';
import express from 'express';
import { imports } from '@leafage/toolkit';
var _useMiddleware = function useMiddleware(ctx, middleware) {
if (!middleware) return ctx;
if (typeof middleware === 'string') {
var handle = imports.importModule(middleware, {
isDev: ctx.context.options.dev,
paths: [import.meta.url, path.join(ctx.context.options.dir.root, ctx.context.options.dir.src), ctx.context.options.dir.root, path.join(ctx.context.options.dir.root, 'node_modules')]
});
return _useMiddleware(handle);
}
if (_typeof(middleware) === 'object') {
var route = middleware.path || '/';
if (typeof middleware.handle === 'string') {
return ctx.app.use(route, express["static"](middleware.handle));
}
return ctx.app.use(route, middleware.handle);
}
return ctx.app.use(middleware);
};
export { _useMiddleware as useMiddleware };