
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@technik-sde/foxy
Advanced tools
> Customizable frontend-proxy, supporting multiple handlers for input-urls
Customizable frontend-proxy, supporting multiple handlers for input-urls
Motivation Our infrastructure may contain different media-services and on different environments. Having a set of nested widgets, libraries and applications they all access the same services within an environment. This frontend-proxy helps to open source applications, since internal ressources and behaviour can be configured, but its public api is consistent and has default handlers for the normal use-case.
yarn add @technik-sde/foxy
Handler A handler registers its methods for a specific request-object, containing a source
-property. The handler will be selected for the exposed request-method, when its function use(RequestObject):boolean
returns true
.
import { Foxy, utils } from "technik-sde/foxy";
const proxy = new Foxy({
handlers: [
{
use({ source }) {
return myUrlFormat.test(source);
},
getImageURL({ source }) {
return Promise.resolve(buildMyUrlScheme(source));
},
getImageInfo({ source }) {
return utils.loadImage(buildMyUrlScheme(source))
}
}
]
});
const finalUrl = await proxy.getImageURL({ source: 1234 });
const imageMetadata = await proxy.getImageInfo({ source: 1234 });
Multiple handlers are supported and are resolved from first to last index. The first handler returning true
on use, will be selected, if the given method-name is defined:
import { Foxy } from "technik-sde/foxy";
const proxy = new Foxy({
handlers: [
{
use({ source }) {
return myUrlFormat.test(source);
},
getImageURL({ source }) {
return Promise.resolve(buildMyUrlScheme(source));
}
},
{
use: () => true,
// overwrites default exception to always return false
getImageURL({ source }) { return Promise.resolve(false); }
}
]
});
const finalUrl = await proxy.getImageURL({ source: "abc" }); // false, when not myUrlFormat
Per default the following methods are supported via api: getImageURL
, getImageInfo
, getVideoURL
, getVideoInfo
. The
generic method get(methodName: string, requestData: AnyObject)
may be used to access any custom methods defined on
handlers. e.g.
import { Foxy } from "technik-sde/foxy";
const proxy = new Foxy({
handlers: [
{
use({ source }) {
return myUrlFormat.test(source);
},
getJSON({ source }) {
return fetch(buildMyUrlScheme(source)).then(response => response.json());
}
}
]
});
const json = await proxy.get("getJSON", { source: "my-json-url" });
Currently three example handlers are exported with this module. They probably should not be used in production:
Import these handlers with
import { handler } from "technik-sde/foxy";
// handler.unsplash
// handler.image
// handler.video
FAQs
> Customizable frontend-proxy, supporting multiple handlers for input-urls
The npm package @technik-sde/foxy receives a total of 2 weekly downloads. As such, @technik-sde/foxy popularity was classified as not popular.
We found that @technik-sde/foxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 48 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.