@leafage/server
Version:
The React Server Side Render Framework
39 lines (35 loc) • 1.59 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
*/
;
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
var path = require('node:path');
var express = require('express');
var toolkit = require('@leafage/toolkit');
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
var _useMiddleware = function useMiddleware(ctx, middleware) {
if (!middleware) return ctx;
if (typeof middleware === 'string') {
var handle = toolkit.imports.importModule(middleware, {
isDev: ctx.context.options.dev,
paths: [(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('common/utils.js', document.baseURI).href)), 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 (_rollupPluginBabelHelpers.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);
};
exports.useMiddleware = _useMiddleware;