Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tinyhttp/cors

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/cors - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

3

dist/index.d.ts

@@ -11,2 +11,3 @@ /// <reference types="node" />

optionsSuccessStatus?: number;
preflightContinue?: boolean;
}

@@ -16,2 +17,2 @@ /**

*/
export declare const cors: ({ origin, methods, allowedHeaders, exposedHeaders, credentials, maxAge, optionsSuccessStatus }: AccessControlOptions) => (req: Request, res: Response, next?: () => void) => void;
export declare const cors: (opts?: AccessControlOptions) => (req: Request, res: Response, next?: () => void) => void;

@@ -6,3 +6,4 @@ import { vary } from 'es-vary';

*/
const cors = ({ origin = '*', methods = ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'], allowedHeaders, exposedHeaders, credentials, maxAge, optionsSuccessStatus = 204 }) => {
const cors = (opts) => {
const { origin = '*', methods = ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'], allowedHeaders, exposedHeaders, credentials, maxAge, optionsSuccessStatus = 204, preflightContinue = false } = opts;
return (req, res, next) => {

@@ -32,7 +33,9 @@ // Checking the type of the origin property

res.setHeader('Access-Control-Max-Age', maxAge);
if (next === undefined) {
if (preflightContinue) {
next === null || next === void 0 ? void 0 : next();
}
else {
res.statusCode = optionsSuccessStatus;
res.end();
}
next === null || next === void 0 ? void 0 : next();
};

@@ -39,0 +42,0 @@ };

{
"name": "@tinyhttp/cors",
"version": "1.1.1",
"version": "1.1.2",
"description": "tinyhttp CORS module",

@@ -5,0 +5,0 @@ "type": "module",

@@ -34,2 +34,3 @@ # @tinyhttp/cors

- `optionsSuccessStatus`: Provides a status code to use for successful OPTIONS requests, since some legacy browsers (IE11, various SmartTVs) choke on 204.
- `preflightContinue`: Set 204 and finish response if `true`, call `next` if false.

@@ -42,3 +43,4 @@ The default configuration is:

"methods": ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
"optionsSuccessStatus": 204
"optionsSuccessStatus": 204,
"preflightContinue": false
}

@@ -55,10 +57,9 @@ ```

app.use(cors({ origin: 'https://myfantastic.site/' }))
app.options('*', cors())
app.get('/', (req, res) => {
res.send('The headers contained in my response are defined in the cors middleware')
})
app.listen(3000)
app
.use(cors({ origin: 'https://myfantastic.site/' }))
.options('*', cors())
.get('/', (req, res) => {
res.send('The headers contained in my response are defined in the cors middleware')
})
.listen(3000)
```

@@ -65,0 +66,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc