title: How to make my API Private by using cors in angular fullstack generator?
body: <p>I am using angular fullstack generator for my web app, I want to make my api a private one, meaning the response should be provided only from my domain. If the api is used from a different domain it should not provide the response.</p>
  
  <p>For this I used the following npm package <a href="https://www.npmjs.com/package/cors" rel="nofollow noreferrer">https://www.npmjs.com/package/cors</a>.</p>
  
  <p>I have added the following code in my project.</p>
  
  <pre><code>'use strict';
  
  var express = require('express');
  var cors = require('cors');
  var router = express.Router();
  var app = express();
  
  var corsOptions = {
    origin: 'http://example.com'
  };
  
  router.get('/', cors(corsOptions), function(req, res, next) {
    res.json({
      msg: 'This is CORS-enabled for only homefuly.com.'
    });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>The above code is placed in my server->api->test->index.js</p>
  
  <p>when I hit the api <a href="http://localhost:9000/api/test" rel="nofollow noreferrer">http://localhost:9000/api/test</a> I am able to see the response.I should only get response if my making request from example.com else it should throw an error message, kindly help to achieve this.</p>
  
  <p>Thanks in advance.</p>