Skip to main content

expressJS

  const app = express();

/**
* Changes made to enable CORS
*/

const allowCrossDomain = (req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, token');

    // intercept OPTIONS method
    if ('OPTIONS' == req.method) {
        res.sendStatus(200);
    }
    else {
        next();
    }
};

//Allow cross domain.
app.use(allowCrossDomain);

Comments

Post a Comment

Popular posts from this blog

12 - HTML 5 and CSS

HTML 5 Question : If I do not put <! DOCTYPE html> will HTML 5 work? Answer : No, browser will not be able to identify that it’s a HTML document and HTML 5 tags will not function properly. Diff between HTML 5 Layout and HTML 4 or previous HTML? Answer : A typical web page has headers, footers, navigation, central area and side bars. Now if we want to represent the same in HTML 4 with proper names to the HTML section we would probably use a DIV tag. But in HTML 5 they have made it more clear by creating element names for those sections which makes your HTML more readable. Below are more details of the HTML 5 elements which form the page structure. <header> : Represents header data of HTML. <footer> : Footer section of the page. <nav> : Navigation elements in the page. <article> : Self-contained content. <section> : Used inside article to define sections or group content in to sections. <aside> : Represent side bar contents of a...

Collections JAVA

Collection Question:Comparable and Comparator? Comparable Comparator Comparable provides single sorting sequence. In other words, we can sort the collection on the basis of single element such as id or name or price etc. Comparator provides multiple sorting sequence. In other words, we can sort the collection on the basis of multiple elements such as id, name and price etc. Comparable affects the original class i.e. actual class is modified. Comparator doesn't affect the original class i.e. actual class is not modified. Comparable provides compareTo() method to sort elements. Comparator provides compare() method to sort elements. Comparable is found in java.lang package. Comparator is found in java.util package. We can sort the list elements of Comparable type byCollections.sort(List) method. We can sort the list elements of Comparator type   byCollections.sort(List,...

Javascript

Question : example of Map Reduce Answer : (() => { let aNumberArray = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ; let sum = aNumberArray. map (data => data * 2 ) . reduce ((ongoing , data) => ongoing + data) ; console . log (sum) ; })() Question : What is IIFE? Answer  : Immediately Invoked function expression e.g. (function(){}()). usually pronounces as " effy ". Question : Why the script tag should be added at the bottom or before the end of the body tag? Answer  : It helps the html page to render quickly without even downloading the script which may be getting downloaded from the slow CDN. there are other alternative like async and defer as well, which are supported primarily on new browsers.     <script src="bower_components/angular/angular.min.js" defer></script>     <script src="bower_components/jquery/dist/jquery.min.js" defer></script>     <script src="bower_components...