@vue-storefront/middleware
Advanced tools
Comparing version 3.9.0 to 3.10.0
import type { Express } from "express"; | ||
import type { IntegrationContext, MiddlewareConfig } from "./types"; | ||
declare function createServer<TIntegrationContext extends Record<string, IntegrationContext>>(config: MiddlewareConfig<TIntegrationContext>): Promise<Express>; | ||
import type { IntegrationContext, MiddlewareConfig, CreateServerOptions } from "./types"; | ||
declare function createServer<TIntegrationContext extends Record<string, IntegrationContext>>(config: MiddlewareConfig<TIntegrationContext>, options?: CreateServerOptions): Promise<Express>; | ||
export { createServer }; | ||
//# sourceMappingURL=createServer.d.ts.map |
@@ -330,13 +330,16 @@ 'use strict'; | ||
async function createServer(config) { | ||
const defaultCorsOptions = { | ||
credentials: true, | ||
origin: ["http://localhost:3000", "http://localhost:4000"], | ||
}; | ||
async function createServer(config, options = {}) { | ||
const app = express__default["default"](); | ||
app.use(express__default["default"].json()); | ||
app.use(cookieParser__default["default"]()); | ||
app.use(cors__default["default"]({ | ||
credentials: true, | ||
origin: "http://localhost:3000", | ||
})); | ||
app.use(express__default["default"].json(options.bodyParser)); | ||
app.use(options.cookieParser | ||
? cookieParser__default["default"](options.cookieParser.secret, options.cookieParser.options) | ||
: cookieParser__default["default"]()); | ||
app.use(cors__default["default"](options.cors ?? defaultCorsOptions)); | ||
app.disable("x-powered-by"); | ||
consola__default["default"].info("Middleware starting...."); | ||
const options = { | ||
const helmetOptions = { | ||
contentSecurityPolicy: false, | ||
@@ -353,3 +356,3 @@ crossOriginOpenerPolicy: false, | ||
if (isHelmetEnabled) { | ||
app.use(helmet__default["default"](options)); | ||
app.use(helmet__default["default"](helmetOptions)); | ||
consola__default["default"].info("VSF `Helmet` middleware added"); | ||
@@ -356,0 +359,0 @@ } |
@@ -318,13 +318,16 @@ import consola from 'consola'; | ||
async function createServer(config) { | ||
const defaultCorsOptions = { | ||
credentials: true, | ||
origin: ["http://localhost:3000", "http://localhost:4000"], | ||
}; | ||
async function createServer(config, options = {}) { | ||
const app = express(); | ||
app.use(express.json()); | ||
app.use(cookieParser()); | ||
app.use(cors({ | ||
credentials: true, | ||
origin: "http://localhost:3000", | ||
})); | ||
app.use(express.json(options.bodyParser)); | ||
app.use(options.cookieParser | ||
? cookieParser(options.cookieParser.secret, options.cookieParser.options) | ||
: cookieParser()); | ||
app.use(cors(options.cors ?? defaultCorsOptions)); | ||
app.disable("x-powered-by"); | ||
consola.info("Middleware starting...."); | ||
const options = { | ||
const helmetOptions = { | ||
contentSecurityPolicy: false, | ||
@@ -341,3 +344,3 @@ crossOriginOpenerPolicy: false, | ||
if (isHelmetEnabled) { | ||
app.use(helmet(options)); | ||
app.use(helmet(helmetOptions)); | ||
consola.info("VSF `Helmet` middleware added"); | ||
@@ -344,0 +347,0 @@ } |
@@ -0,1 +1,4 @@ | ||
import { CorsOptions, CorsOptionsDelegate } from "cors"; | ||
import bodyParser from "body-parser"; | ||
import cookieParser from "cookie-parser"; | ||
import { TObject } from "./base"; | ||
@@ -71,2 +74,31 @@ import { ApiClientExtension, ApiMethods, ApiMethodsFactory, MiddlewareContext } from "./common"; | ||
export type CreateApiProxyFn = <CONFIG, API, CLIENT>(givenConfig: any, customApi?: any) => ApiInstance<CONFIG, API, CLIENT>; | ||
export interface CreateServerOptions { | ||
/** | ||
* The options for the `express.json` middleware. | ||
* If not provided, the default options will be used. | ||
* @see https://www.npmjs.com/package/body-parser | ||
*/ | ||
bodyParser?: bodyParser.OptionsJson; | ||
/** | ||
* The options for the `cookie-parser` middleware. | ||
* If not provided, the default options will be used. | ||
* @see https://www.npmjs.com/package/cookie-parser | ||
*/ | ||
cookieParser?: { | ||
secret: string | string[]; | ||
options: cookieParser.CookieParseOptions; | ||
}; | ||
/** | ||
* The options for the `cors` middleware. | ||
* If not provided, the following configuration will be used: | ||
* ```json | ||
* { | ||
* "credentials": true, | ||
* "origin": ["http://localhost:3000", "http://localhost:4000"] | ||
* } | ||
* ``` | ||
* @see https://www.npmjs.com/package/cors | ||
*/ | ||
cors?: CorsOptions | CorsOptionsDelegate; | ||
} | ||
//# sourceMappingURL=server.d.ts.map |
{ | ||
"name": "@vue-storefront/middleware", | ||
"version": "3.9.0", | ||
"version": "3.10.0", | ||
"main": "lib/index.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "lib/index.es.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
78487
1356