Skip to content

Commit

Permalink
Adding cors and body-parser
Browse files Browse the repository at this point in the history
Adding cors and body-parser
  • Loading branch information
Wathfea committed Sep 3, 2024
1 parent af440c7 commit cb10133
Show file tree
Hide file tree
Showing 14 changed files with 913 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');

const corsOptions = {
origin: '*',
methods: 'GET, HEAD, PUT, PATCH, POST, DELETE',
credentials: true,
optionsSuccessStatus: 204
};

const app = express()
const PORT = 8000

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.use(cors(corsOptions));
app.options('*', cors(corsOptions)); // Enable pre-flight

app.get('/', (req, res) => {
res.send('Hello World')
Expand All @@ -13,7 +27,7 @@ app.get('/about', (req, res) => {

const start = () => {
try {
const port = process.env.PORT || 3000;
const port = 3000;
app.listen(port, () =>
console.log(`✅ Server is listening on port ${port}.........`)
);
Expand Down
22 changes: 22 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions node_modules/cors/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions node_modules/cors/HISTORY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions node_modules/cors/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cb10133

Please sign in to comment.