Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Enabled cors #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion template/node10-express-arm64/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same //

app.delete('/*', middleware);

const port = process.env.http_port || 3000;
Expand Down
1 change: 1 addition & 0 deletions template/node10-express-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.2",
"cors": "^2.8.5",
"express": "^4.16.2"
}
}
7 changes: 6 additions & 1 deletion template/node10-express-armhf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions template/node10-express-armhf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.2",
"cors": "^2.8.5",
"express": "^4.16.2"
}
}
7 changes: 6 additions & 1 deletion template/node10-express/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • comment not useful
  • prefer single quote

// app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(bodyParser.raw());
Expand Down Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use an instance Router instead of duplicating app.use(cors());

app.delete('/*', middleware);

const port = process.env.http_port || 3000;
Expand Down
1 change: 1 addition & 0 deletions template/node10-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.2",
"cors": "^2.8.5",
"express": "^4.16.2"
}
}