Skip to content

Commit

Permalink
Merge pull request #34 from buildingu/chore-fix-cors-issue
Browse files Browse the repository at this point in the history
CORS Fix Attempt
  • Loading branch information
gbudjeakp authored Jul 8, 2024
2 parents 183d1a8 + 3a14f42 commit 15d362f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 19 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
const express = require('express');
const cors = require('cors')
const cookieParser = require('cookie-parser');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const app = express();
const port = process.env.PORT || 5001
const port = process.env.PORT || 5001;

//////Express MiddleWares//////////////

const prodOrigin = "https://buildingu.github.io"
const prodOrigin = "https://buildingu.github.io";

//Use for local development
// const devOrigin = "http://localhost:5173"
// const devOrigin = "http://localhost:5173";

const corsOptions = {
origin: prodOrigin,
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
allowedHeaders: ['Content-Type', 'Authorization'],
};

app.use(cors(corsOptions))
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.use(cors(corsOptions));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cookieParser());

// Handle preflight requests
app.options('*', cors(corsOptions));

const usersRouter = require('./Routes/User');
const feedbackRouter = require('./Routes/Feedback');
const passwordRouter = require('./Routes/Password');
const passwordRouter = require('./Routes/Password');

app.use('/api/users', usersRouter);
app.use('/api/feedback', feedbackRouter);
app.use('/api/password', passwordRouter);

app.get('/',(req, res)=>{
res.redirect('https://buildingu.github.io/Building-u-feedback/');
})
app.get('/', (req, res) => {
res.redirect('https://buildingu.github.io/Building-u-feedback/');
});


app.listen(port, ()=>{
console.log(`HTTP Server listening on port ${port}`);
})
app.listen(port, () => {
console.log(`HTTP Server listening on port ${port}`);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "building-u-feedback-api",
"version": "v0.4.1-alpha",
"version": "v0.4.2-alpha",
"description": "This is for the server api that serves the app",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 15d362f

Please sign in to comment.