Skip to content

Naman-Kumar-Sinha/cdc-state-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cross Domain Cookie State Management

TIP #1: Use ngrok to tunnel your localhost port 80.

TIP #2: To get the client code, check this snippet or scroll all the way to the bottom.

Functions

checkResource(req, res, next)

Check API resource and skip first middleware for specific resource

specificCors(req, res, next)

Sets Specific CORS Reponse headers

genCors(req, res, next)

Sets General CORS Response headers

checkResource(req, res, next)

Check API resource and skip first middleware for specific resource

Kind: global function

Param Type Description
req * HTTP Request object
res * HTTP Response object
next * Method executes next middleware

specificCors(req, res, next)

Sets Specific CORS Reponse headers

Kind: global function

Param Type Description
req * HTTP Request object
res * HTTP Response object
next * Method executes next middleware

genCors(req, res, next)

Sets General CORS Response headers

Kind: global function

Param Type Description
req * HTTP Request object
res * HTTP Response object
next * Method executes next middleware

Client-side AJAX Request Snippet

Put this in your HTML and you are good to go. Make sure you've a demo element in your HTML code to render the contents.

<script>
    function loadDoc() {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("demo").innerHTML = this.responseText;
            }
        };
        xhttp.open("GET", "https://cdc-state-management.herokuapp.com/api/cookies", true);
        /*If you are looking for cookies from cross-domain then xhttp.withCredentials is mandatory.
        */
        xhttp.withCredentials = true;
        xhttp.send();
    }
</script>

LICENSE

MIT License

Releases

No releases published

Packages

No packages published