-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from buildingu/chore-fix-cors-issue
CORS Fix Attempt
- Loading branch information
Showing
2 changed files
with
20 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters