1var express = require('express')
2var cors = require('cors')
3var app = express()
4
5app.use(cors())
6
7app.get('/products/:id', function (req, res, next) {
8 res.json({msg: 'This is CORS-enabled for all origins!'})
9})
10
11app.listen(80, function () {
12 console.log('CORS-enabled web server listening on port 80')
13})
14
1/*index.js*/
2const express = require( 'express' );
3const cors = require( 'cors' );
4const app = express(); const port = 3030;
5//cors is enabled through out the entire app
6app.use( cors() );
7app.get( '/users', (request, response, next) => { res.json( { info: 'cors is enabled' } ) });
8app.listen( port, () => {
9 console.log(`App is running on ${port}`)
10 });