-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Server: Add handling for custom middleware
As per RFC 0005: SAP/ui5-tooling#151
- Loading branch information
1 parent
840dfb9
commit b467f49
Showing
9 changed files
with
228 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const ui5connect = require("connect-openui5"); | ||
|
||
function createMiddleware() { | ||
return ui5connect.proxy({ | ||
secure: false | ||
}); | ||
} | ||
|
||
module.exports = createMiddleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const middlewares = { | ||
compression: "compression", | ||
cors: "cors", | ||
csp: "./csp", | ||
serveResources: "./serveResources", | ||
serveIndex: "./serveIndex", | ||
discovery: "./discovery", | ||
versionInfo: "./versionInfo", | ||
connectUi5Proxy: "./connectUi5Proxy", | ||
serveThemes: "./serveThemes", | ||
nonReadRequests: "./nonReadRequests" | ||
}; | ||
|
||
function getMiddleware(middlewareName) { | ||
const middlewarePath = middlewares[middlewareName]; | ||
|
||
if (!middlewarePath) { | ||
throw new Error(`middlewareRepository: Unknown Middleware ${middlewareName}`); | ||
} | ||
return require(middlewarePath); | ||
} | ||
|
||
function addMiddleware(name, middlewarePath) { | ||
if (middlewares[name]) { | ||
throw new Error(`middlewareRepository: Middleware ${name} already registered`); | ||
} | ||
middlewares[name] = middlewarePath; | ||
} | ||
|
||
function getAllMiddleware() { | ||
const modules = {}; | ||
for (const middlewareName in middlewares) { | ||
if (middlewares.hasOwnProperty(middlewareName)) { | ||
modules[middlewareName] = require(middlewares[middlewareName]); | ||
} | ||
} | ||
return middlewares; | ||
} | ||
|
||
module.exports = { | ||
getMiddleware: getMiddleware, | ||
addMiddleware: addMiddleware, | ||
getAllMiddleware: getAllMiddleware | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.