Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions lib/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import {parse as parseUrl} from "node:url";
import http from "node:http";
import https from "node:https";
import httpProxy from "http-proxy";
import {statSync, readFileSync} from "node:fs";
import {statSync, readFileSync, existsSync} from "node:fs";
import path from "node:path";
import {fileURLToPath} from "node:url";
import yaml from "js-yaml";
import {Router} from "express";
import {ErrorMessage} from "./errors.js";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default class Framework {
Expand Down Expand Up @@ -547,12 +546,42 @@ export default class Framework {
req.url = this.rewriteUrl(req.url);
next();
}

/**
* For Maven-managed UI5 libraries (fiori pipeline), dependencies are extracted to the
* target/dependency/META-INF/resources directory inside the project. This middleware
* returns the file contents if found inside the dependency directory.
*
* @param {http.ClientRequest} req Client request object
* @param {http.ServerResponse} res Server response object
* @param {Function} next Next middleware
* @returns {void}
*/
middlewareMavenDependencies(req, res, next) {
const sMvnDependencyDir = path.resolve("./target/dependency/META-INF/resources");
if (req.method !== "GET" || !existsSync(sMvnDependencyDir)) {
next();
return;
}
const oReqUrl = parseUrl(req.url);
const sPath = oReqUrl.pathname;
if (sPath.startsWith("/base/resources")) {
const sSearchPath = path.resolve(sMvnDependencyDir + sPath.substring("/base/resources".length));
if (existsSync(sSearchPath)) {
const oBody = readFileSync(sSearchPath);
res.write(oBody);
res.statusCode = 200;
res.end();
return;
}
}
next();
}
async setupMiddleware() {
const config = this.config;

if (config.ui5.type === "library") {
config.ui5._beforeMiddleware = new Router();
config.ui5._beforeMiddleware.use(this.middlewareMavenDependencies.bind(this));
config.ui5._beforeMiddleware.use(this.beforeMiddlewareRewriteUrl.bind(this));
config.beforeMiddleware.push("ui5--beforeMiddleware");
}
Expand Down