diff --git a/template/node10-express-arm64/index.js b/template/node10-express-arm64/index.js index 8c85f48..240cc50 100644 --- a/template/node10-express-arm64/index.js +++ b/template/node10-express-arm64/index.js @@ -7,7 +7,7 @@ const express = require('express') const app = express() const handler = require('./function/handler'); const bodyParser = require('body-parser') - +const cors = require("cors");// imported cors package // app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.use(bodyParser.raw()); @@ -80,10 +80,15 @@ var middleware = (req, res) => { handler(fnEvent, fnContext, cb); }; +app.use(cors());// enabled cors app.post('/*', middleware); +app.use(cors());// enabled cors app.get('/*', middleware); +app.use(cors());// enabled cors app.patch('/*', middleware); +app.use(cors());// enabled cors app.put('/*', middleware); +app.use(cors());// enabled cors app.delete('/*', middleware); const port = process.env.http_port || 3000; diff --git a/template/node10-express-arm64/package.json b/template/node10-express-arm64/package.json index 51b667c..522fff1 100644 --- a/template/node10-express-arm64/package.json +++ b/template/node10-express-arm64/package.json @@ -11,6 +11,7 @@ "license": "ISC", "dependencies": { "body-parser": "^1.18.2", + "cors": "^2.8.5", "express": "^4.16.2" } } diff --git a/template/node10-express-armhf/index.js b/template/node10-express-armhf/index.js index 8c85f48..240cc50 100644 --- a/template/node10-express-armhf/index.js +++ b/template/node10-express-armhf/index.js @@ -7,7 +7,7 @@ const express = require('express') const app = express() const handler = require('./function/handler'); const bodyParser = require('body-parser') - +const cors = require("cors");// imported cors package // app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.use(bodyParser.raw()); @@ -80,10 +80,15 @@ var middleware = (req, res) => { handler(fnEvent, fnContext, cb); }; +app.use(cors());// enabled cors app.post('/*', middleware); +app.use(cors());// enabled cors app.get('/*', middleware); +app.use(cors());// enabled cors app.patch('/*', middleware); +app.use(cors());// enabled cors app.put('/*', middleware); +app.use(cors());// enabled cors app.delete('/*', middleware); const port = process.env.http_port || 3000; diff --git a/template/node10-express-armhf/package.json b/template/node10-express-armhf/package.json index 51b667c..522fff1 100644 --- a/template/node10-express-armhf/package.json +++ b/template/node10-express-armhf/package.json @@ -11,6 +11,7 @@ "license": "ISC", "dependencies": { "body-parser": "^1.18.2", + "cors": "^2.8.5", "express": "^4.16.2" } } diff --git a/template/node10-express/index.js b/template/node10-express/index.js index 8c85f48..240cc50 100644 --- a/template/node10-express/index.js +++ b/template/node10-express/index.js @@ -7,7 +7,7 @@ const express = require('express') const app = express() const handler = require('./function/handler'); const bodyParser = require('body-parser') - +const cors = require("cors");// imported cors package // app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.use(bodyParser.raw()); @@ -80,10 +80,15 @@ var middleware = (req, res) => { handler(fnEvent, fnContext, cb); }; +app.use(cors());// enabled cors app.post('/*', middleware); +app.use(cors());// enabled cors app.get('/*', middleware); +app.use(cors());// enabled cors app.patch('/*', middleware); +app.use(cors());// enabled cors app.put('/*', middleware); +app.use(cors());// enabled cors app.delete('/*', middleware); const port = process.env.http_port || 3000; diff --git a/template/node10-express/package.json b/template/node10-express/package.json index 51b667c..522fff1 100644 --- a/template/node10-express/package.json +++ b/template/node10-express/package.json @@ -11,6 +11,7 @@ "license": "ISC", "dependencies": { "body-parser": "^1.18.2", + "cors": "^2.8.5", "express": "^4.16.2" } }