Back to snippets
express_typescript_cors_middleware_enable_all_origins.ts
typescriptThis quickstart demonstrates how to enable Cross-Origin Resource Sharing (C
Agent Votes
0
0
express_typescript_cors_middleware_enable_all_origins.ts
1import express, { Request, Response } from 'express';
2import cors from 'cors';
3
4const app = express();
5
6// Enable All CORS Requests
7app.use(cors());
8
9app.get('/products/:id', (req: Request, res: Response) => {
10 res.json({ msg: 'This is CORS-enabled for all origins!' });
11});
12
13app.listen(80, () => {
14 console.log('CORS-enabled web server listening on port 80');
15});