-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2536533
commit b59884d
Showing
2 changed files
with
21 additions
and
11 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 |
---|---|---|
|
@@ -8,9 +8,21 @@ import ProjectNameModel from './schema.mjs'; // Import your Mongoose model | |
|
||
const app = express(); // Initialize Express app | ||
|
||
// Middleware setup | ||
// Allow specific origins (replace with your Vercel frontend URL) | ||
const allowedOrigins = ['https://blockscan-swin.vercel.app']; | ||
|
||
const corsOptions = { | ||
origin: function (origin, callback) { | ||
if (allowedOrigins.indexOf(origin) !== -1 || !origin) { | ||
callback(null, true); | ||
} else { | ||
callback(new Error('Not allowed by CORS')); | ||
} | ||
}, | ||
}; | ||
|
||
app.use(cors(corsOptions)); // Use CORS with the options | ||
app.use(express.json()); // Parse JSON requests | ||
app.use(cors({ origin: '*' })); // Enable CORS for all origins | ||
|
||
// MongoDB connection | ||
const mongoUrl = "mongodb+srv://leviron:[email protected]/BlockScanDB?retryWrites=true&w=majority&appName=BlockScan"; | ||
|
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