npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

defaultjs-httpinterceptor

v1.0.0-beta.5

Published

this helps you to intercept request at websites for oauth2 or token autentications or even what you need

Downloads

8

Readme

de.titus.request.interceptor

This lib provide an function to intercept requests and change the orginal request in html sites. The main use case is to make sso authentications in enterprise environment with microservices.

The web site from service A with url https://service-a.com want to call an ajax request from service B with url https://service-b.com. The main challenge for the developer is, how to authenticate the user at service B. If you calling only some different services and you know all the services, you solve the problem with custom code to make the authentication to the services.

BUT, if you don't know all the services, because you have an web portal or something else, or you have an high number of services to include, then you can do the authentication with this libs, very easily.

How to include

at HTML page

With NPM

Sample for JWT

RequestInterceptManager.addInterceptor("[service-b","service-b", "service-...", new de.titus.request.interceptor.interceptors.JWTInterceptor({
	login : {
		url : "url to get json web token",
		method: "GET", //"POST", ...
		body : "[optional]",
		response : { // how to change the interceped request
			type: "authentication-header",
			headerType: "Bearer",
			valueType : "content",
			valueSelector: "jwt"
		}			
	},	
	refresh : {
		interval: 10000 // default refresh interval time in ms to refresh the token
		//interval: "always" // this tells, that refresh the jwt at every request 
	} 
}));

Custom Interceptor

as simple function

RequestInterceptManager.addInterceptor("[service-b","service-b", "service-...", function(aData, aRequest, aCallback){
	// You need to check, if it is a XMLHttpRequest, because XMLHttpRequest an fetch working differently
	let isXHR = aRequest instanceof XMLHttpRequest; 

	if(isXHR)
		aRequest.setRequestHeader("myHeader" , "my value");
	else{
		aRequest.headers = aRequest.headers || {}
		aRequest.headers["myHeader"] = "my value";
	} 
});

as simple as object


let MyInterceptor = function(){
	this.lastCall;
}; 

MyInterceptor.prototype.onHandle = function(aData, aRequest, aCallback){
	// You need to check, if it is a XMLHttpRequest, because XMLHttpRequest an fetch working differently
	let isXHR = aRequest instanceof XMLHttpRequest; 

	if(isXHR)
		aRequest.setRequestHeader("myHeader" , "my value");
	else{
		aRequest.headers = aRequest.headers || {}
		aRequest.headers["myHeader"] = "my value";
	} 
	
	this.lastCall = Date.now();
};

RequestInterceptManager.addInterceptor("[service-b","service-b", "service-...", new MyInterceptor());