Преглед изворни кода

feat(core): Add trustProxy option to ApiOptions (#3567)

gabriellbui пре 7 месеци
родитељ
комит
f24871965c
26 измењених фајлова са 95 додато и 24 уклоњено
  1. 18 0
      docs/docs/guides/deployment/production-configuration/index.md
  2. 1 1
      docs/docs/reference/typescript-api/assets/asset-options.md
  3. 1 1
      docs/docs/reference/typescript-api/auth/auth-options.md
  4. 1 1
      docs/docs/reference/typescript-api/auth/cookie-options.md
  5. 1 1
      docs/docs/reference/typescript-api/auth/superadmin-credentials.md
  6. 2 2
      docs/docs/reference/typescript-api/common/bootstrap.md
  7. 6 0
      docs/docs/reference/typescript-api/configuration/api-options.md
  8. 1 1
      docs/docs/reference/typescript-api/configuration/entity-options.md
  9. 1 1
      docs/docs/reference/typescript-api/configuration/runtime-vendure-config.md
  10. 1 1
      docs/docs/reference/typescript-api/configuration/system-options.md
  11. 23 0
      docs/docs/reference/typescript-api/configuration/trust-proxy-options.md
  12. 1 1
      docs/docs/reference/typescript-api/configuration/vendure-config.md
  13. 1 1
      docs/docs/reference/typescript-api/import-export/import-export-options.md
  14. 1 1
      docs/docs/reference/typescript-api/job-queue/job-queue-options.md
  15. 1 1
      docs/docs/reference/typescript-api/orders/order-options.md
  16. 1 1
      docs/docs/reference/typescript-api/payment/payment-options.md
  17. 1 1
      docs/docs/reference/typescript-api/products-stock/catalog-options.md
  18. 1 1
      docs/docs/reference/typescript-api/promotions/promotion-options.md
  19. 1 1
      docs/docs/reference/typescript-api/scheduled-tasks/scheduler-options.md
  20. 1 1
      docs/docs/reference/typescript-api/shipping/shipping-options.md
  21. 1 1
      docs/docs/reference/typescript-api/tax/tax-options.md
  22. 2 2
      docs/docs/reference/typescript-api/worker/bootstrap-worker.md
  23. 5 3
      packages/core/src/bootstrap.ts
  24. 1 0
      packages/core/src/config/default-config.ts
  25. 20 0
      packages/core/src/config/vendure-config.ts
  26. 1 0
      packages/create/templates/vendure-config.hbs

+ 18 - 0
docs/docs/guides/deployment/production-configuration/index.md

@@ -117,6 +117,24 @@ show timezone;
 ```
 ```
 and you should expect to see `UTC` or `Etc/UTC`.
 and you should expect to see `UTC` or `Etc/UTC`.
 
 
+## Trust proxy
+
+When deploying your Vendure application behind a reverse proxy (usually the case with most hosting services), consider configuring Express's `trust proxy` setting. This allows you to retrieve the original IP address from the `X-Forwarded-For` header, which proxies use to forward the client's IP address.
+
+You can set the `trustProxy` option in your `VendureConfig`:
+
+```ts
+import { VendureConfig } from '@vendure/core';
+
+export const config: VendureConfig = {
+    apiOptions: {
+        trustProxy: 1, // Trust the first proxy in front of your app
+    },
+};
+```
+
+For more details on configuring `trust proxy`, refer to the [Express documentation](https://expressjs.com/en/guide/behind-proxies.html).
+
 ## Security Considerations
 ## Security Considerations
 
 
 Please read over the [Security](/guides/developer-guide/security) section of the Developer Guide for more information on how to secure your Vendure application.
 Please read over the [Security](/guides/developer-guide/security) section of the Developer Guide for more information on how to secure your Vendure application.

+ 1 - 1
docs/docs/reference/typescript-api/assets/asset-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## AssetOptions
 ## AssetOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="653" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="671" packageName="@vendure/core" />
 
 
 The AssetOptions define how assets (images and other files) are named and stored, and how preview images are generated.
 The AssetOptions define how assets (images and other files) are named and stored, and how preview images are generated.
 
 

+ 1 - 1
docs/docs/reference/typescript-api/auth/auth-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## AuthOptions
 ## AuthOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="338" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="356" packageName="@vendure/core" />
 
 
 The AuthOptions define how authentication and authorization is managed.
 The AuthOptions define how authentication and authorization is managed.
 
 

+ 1 - 1
docs/docs/reference/typescript-api/auth/cookie-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## CookieOptions
 ## CookieOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="233" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="251" packageName="@vendure/core" />
 
 
 Options for the handling of the cookies used to track sessions (only applicable if
 Options for the handling of the cookies used to track sessions (only applicable if
 `authOptions.tokenMethod` is set to `'cookie'`). These options are passed directly
 `authOptions.tokenMethod` is set to `'cookie'`). These options are passed directly

+ 1 - 1
docs/docs/reference/typescript-api/auth/superadmin-credentials.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## SuperadminCredentials
 ## SuperadminCredentials
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="829" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="847" packageName="@vendure/core" />
 
 
 These credentials will be used to create the Superadmin user & administrator
 These credentials will be used to create the Superadmin user & administrator
 when Vendure first bootstraps.
 when Vendure first bootstraps.

+ 2 - 2
docs/docs/reference/typescript-api/common/bootstrap.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## bootstrap
 ## bootstrap
 
 
-<GenerationInfo sourceFile="packages/core/src/bootstrap.ts" sourceLine="159" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/bootstrap.ts" sourceLine="160" packageName="@vendure/core" />
 
 
 Bootstraps the Vendure server. This is the entry point to the application.
 Bootstraps the Vendure server. This is the entry point to the application.
 
 
@@ -87,7 +87,7 @@ Parameters
 
 
 ## BootstrapOptions
 ## BootstrapOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/bootstrap.ts" sourceLine="41" packageName="@vendure/core" since="2.2.0" />
+<GenerationInfo sourceFile="packages/core/src/bootstrap.ts" sourceLine="42" packageName="@vendure/core" since="2.2.0" />
 
 
 Additional options that can be used to configure the bootstrap process of the
 Additional options that can be used to configure the bootstrap process of the
 Vendure server.
 Vendure server.

+ 6 - 0
docs/docs/reference/typescript-api/configuration/api-options.md

@@ -33,6 +33,7 @@ interface ApiOptions {
     channelTokenKey?: string;
     channelTokenKey?: string;
     cors?: boolean | CorsOptions;
     cors?: boolean | CorsOptions;
     middleware?: Middleware[];
     middleware?: Middleware[];
+    trustProxy?: TrustProxyOptions;
     apolloServerPlugins?: ApolloServerPlugin[];
     apolloServerPlugins?: ApolloServerPlugin[];
     introspection?: boolean;
     introspection?: boolean;
 }
 }
@@ -125,6 +126,11 @@ Set the CORS handling for the server. See the [express CORS docs](https://github
 <MemberInfo kind="property" type={`<a href='/reference/typescript-api/common/middleware#middleware'>Middleware</a>[]`} default={`[]`}   />
 <MemberInfo kind="property" type={`<a href='/reference/typescript-api/common/middleware#middleware'>Middleware</a>[]`} default={`[]`}   />
 
 
 Custom Express or NestJS middleware for the server. More information can be found in the <a href='/reference/typescript-api/common/middleware#middleware'>Middleware</a> docs.
 Custom Express or NestJS middleware for the server. More information can be found in the <a href='/reference/typescript-api/common/middleware#middleware'>Middleware</a> docs.
+### trustProxy
+
+<MemberInfo kind="property" type={`<a href='/reference/typescript-api/configuration/trust-proxy-options#trustproxyoptions'>TrustProxyOptions</a>`} default={`false`}   />
+
+Set the trust proxy configuration for the server. See the [express proxy docs](https://expressjs.com/en/guide/behind-proxies.html).
 ### apolloServerPlugins
 ### apolloServerPlugins
 
 
 <MemberInfo kind="property" type={`ApolloServerPlugin[]`} default={`[]`}   />
 <MemberInfo kind="property" type={`ApolloServerPlugin[]`} default={`[]`}   />

+ 1 - 1
docs/docs/reference/typescript-api/configuration/entity-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## EntityOptions
 ## EntityOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="1014" packageName="@vendure/core" since="1.3.0" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="1032" packageName="@vendure/core" since="1.3.0" />
 
 
 Options relating to the internal handling of entities.
 Options relating to the internal handling of entities.
 
 

+ 1 - 1
docs/docs/reference/typescript-api/configuration/runtime-vendure-config.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## RuntimeVendureConfig
 ## RuntimeVendureConfig
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="1278" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="1296" packageName="@vendure/core" />
 
 
 This interface represents the VendureConfig object available at run-time, i.e. the user-supplied
 This interface represents the VendureConfig object available at run-time, i.e. the user-supplied
 config values have been merged with the <a href='/reference/typescript-api/configuration/default-config#defaultconfig'>defaultConfig</a> values.
 config values have been merged with the <a href='/reference/typescript-api/configuration/default-config#defaultconfig'>defaultConfig</a> values.

+ 1 - 1
docs/docs/reference/typescript-api/configuration/system-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## SystemOptions
 ## SystemOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="1103" packageName="@vendure/core" since="1.6.0" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="1121" packageName="@vendure/core" since="1.6.0" />
 
 
 Options relating to system functions.
 Options relating to system functions.
 
 

+ 23 - 0
docs/docs/reference/typescript-api/configuration/trust-proxy-options.md

@@ -0,0 +1,23 @@
+---
+title: "TrustProxyOptions"
+isDefaultIndex: false
+generated: true
+---
+<!-- This file was generated from the Vendure source. Do not modify. Instead, re-run the "docs:build" script -->
+import MemberInfo from '@site/src/components/MemberInfo';
+import GenerationInfo from '@site/src/components/GenerationInfo';
+import MemberDescription from '@site/src/components/MemberDescription';
+
+
+## TrustProxyOptions
+
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="241" packageName="@vendure/core" />
+
+Configures Express trust proxy settings when running behind a reverse proxy (usually the case with most hosting services).
+Setting `trustProxy` allows you to retrieve the original IP address from the `X-Forwarded-For` header.
+
+See the [express documentation](https://expressjs.com/en/guide/behind-proxies.html) for more details.
+
+```ts title="Signature"
+type TrustProxyOptions = boolean | number | string | string[] | ((ip: string) => boolean)
+```

+ 1 - 1
docs/docs/reference/typescript-api/configuration/vendure-config.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## VendureConfig
 ## VendureConfig
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="1141" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="1159" packageName="@vendure/core" />
 
 
 All possible configuration options are defined by the
 All possible configuration options are defined by the
 [`VendureConfig`](https://github.com/vendure-ecommerce/vendure/blob/master/packages/core/src/config/vendure-config.ts) interface.
 [`VendureConfig`](https://github.com/vendure-ecommerce/vendure/blob/master/packages/core/src/config/vendure-config.ts) interface.

+ 1 - 1
docs/docs/reference/typescript-api/import-export/import-export-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## ImportExportOptions
 ## ImportExportOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="914" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="932" packageName="@vendure/core" />
 
 
 Options related to importing & exporting data.
 Options related to importing & exporting data.
 
 

+ 1 - 1
docs/docs/reference/typescript-api/job-queue/job-queue-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## JobQueueOptions
 ## JobQueueOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="938" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="956" packageName="@vendure/core" />
 
 
 Options related to the built-in job queue.
 Options related to the built-in job queue.
 
 

+ 1 - 1
docs/docs/reference/typescript-api/orders/order-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## OrderOptions
 ## OrderOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="499" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="517" packageName="@vendure/core" />
 
 
 
 
 
 

+ 1 - 1
docs/docs/reference/typescript-api/payment/payment-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## PaymentOptions
 ## PaymentOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="851" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="869" packageName="@vendure/core" />
 
 
 Defines payment-related options in the <a href='/reference/typescript-api/configuration/vendure-config#vendureconfig'>VendureConfig</a>.
 Defines payment-related options in the <a href='/reference/typescript-api/configuration/vendure-config#vendureconfig'>VendureConfig</a>.
 
 

+ 1 - 1
docs/docs/reference/typescript-api/products-stock/catalog-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## CatalogOptions
 ## CatalogOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="700" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="718" packageName="@vendure/core" />
 
 
 Options related to products and collections.
 Options related to products and collections.
 
 

+ 1 - 1
docs/docs/reference/typescript-api/promotions/promotion-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## PromotionOptions
 ## PromotionOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="762" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="780" packageName="@vendure/core" />
 
 
 
 
 
 

+ 1 - 1
docs/docs/reference/typescript-api/scheduled-tasks/scheduler-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## SchedulerOptions
 ## SchedulerOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="977" packageName="@vendure/core" since="3.3.0" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="995" packageName="@vendure/core" since="3.3.0" />
 
 
 Options related to scheduled tasks..
 Options related to scheduled tasks..
 
 

+ 1 - 1
docs/docs/reference/typescript-api/shipping/shipping-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## ShippingOptions
 ## ShippingOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="778" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="796" packageName="@vendure/core" />
 
 
 
 
 
 

+ 1 - 1
docs/docs/reference/typescript-api/tax/tax-options.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## TaxOptions
 ## TaxOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="891" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/config/vendure-config.ts" sourceLine="909" packageName="@vendure/core" />
 
 
 
 
 
 

+ 2 - 2
docs/docs/reference/typescript-api/worker/bootstrap-worker.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 
 ## bootstrapWorker
 ## bootstrapWorker
 
 
-<GenerationInfo sourceFile="packages/core/src/bootstrap.ts" sourceLine="223" packageName="@vendure/core" />
+<GenerationInfo sourceFile="packages/core/src/bootstrap.ts" sourceLine="225" packageName="@vendure/core" />
 
 
 Bootstraps a Vendure worker. Resolves to a <a href='/reference/typescript-api/worker/vendure-worker#vendureworker'>VendureWorker</a> object containing a reference to the underlying
 Bootstraps a Vendure worker. Resolves to a <a href='/reference/typescript-api/worker/vendure-worker#vendureworker'>VendureWorker</a> object containing a reference to the underlying
 NestJs [standalone application](https://docs.nestjs.com/standalone-applications) as well as convenience
 NestJs [standalone application](https://docs.nestjs.com/standalone-applications) as well as convenience
@@ -51,7 +51,7 @@ Parameters
 
 
 ## BootstrapWorkerOptions
 ## BootstrapWorkerOptions
 
 
-<GenerationInfo sourceFile="packages/core/src/bootstrap.ts" sourceLine="82" packageName="@vendure/core" since="2.2.0" />
+<GenerationInfo sourceFile="packages/core/src/bootstrap.ts" sourceLine="83" packageName="@vendure/core" since="2.2.0" />
 
 
 Additional options that can be used to configure the bootstrap process of the
 Additional options that can be used to configure the bootstrap process of the
 Vendure worker.
 Vendure worker.

+ 5 - 3
packages/core/src/bootstrap.ts

@@ -2,12 +2,13 @@ import { DynamicModule, INestApplication, INestApplicationContext } from '@nestj
 import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
 import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
 import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
 import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
 import { NestFactory } from '@nestjs/core';
 import { NestFactory } from '@nestjs/core';
+import { NestExpressApplication } from '@nestjs/platform-express';
 import { getConnectionToken } from '@nestjs/typeorm';
 import { getConnectionToken } from '@nestjs/typeorm';
 import { DEFAULT_COOKIE_NAME } from '@vendure/common/lib/shared-constants';
 import { DEFAULT_COOKIE_NAME } from '@vendure/common/lib/shared-constants';
 import { Type } from '@vendure/common/lib/shared-types';
 import { Type } from '@vendure/common/lib/shared-types';
-import cookieSession = require('cookie-session');
 import { satisfies } from 'semver';
 import { satisfies } from 'semver';
 import { Connection, DataSourceOptions, EntitySubscriberInterface } from 'typeorm';
 import { Connection, DataSourceOptions, EntitySubscriberInterface } from 'typeorm';
+import cookieSession = require('cookie-session');
 
 
 import { InternalServerError } from './common/error/errors';
 import { InternalServerError } from './common/error/errors';
 import { getConfig, setConfig } from './config/config-helpers';
 import { getConfig, setConfig } from './config/config-helpers';
@@ -170,15 +171,16 @@ export async function bootstrap(
     // eslint-disable-next-line
     // eslint-disable-next-line
     const appModule = await import('./app.module.js');
     const appModule = await import('./app.module.js');
     setProcessContext('server');
     setProcessContext('server');
-    const { hostname, port, cors, middleware } = config.apiOptions;
+    const { hostname, port, cors, middleware, trustProxy } = config.apiOptions;
     DefaultLogger.hideNestBoostrapLogs();
     DefaultLogger.hideNestBoostrapLogs();
-    const app = await NestFactory.create(appModule.AppModule, {
+    const app = await NestFactory.create<NestExpressApplication>(appModule.AppModule, {
         cors,
         cors,
         logger: new Logger(),
         logger: new Logger(),
         ...options?.nestApplicationOptions,
         ...options?.nestApplicationOptions,
     });
     });
     DefaultLogger.restoreOriginalLogLevel();
     DefaultLogger.restoreOriginalLogLevel();
     app.useLogger(new Logger());
     app.useLogger(new Logger());
+    app.set('trust proxy', trustProxy);
     const { tokenMethod } = config.authOptions;
     const { tokenMethod } = config.authOptions;
     const usingCookie =
     const usingCookie =
         tokenMethod === 'cookie' || (Array.isArray(tokenMethod) && tokenMethod.includes('cookie'));
         tokenMethod === 'cookie' || (Array.isArray(tokenMethod) && tokenMethod.includes('cookie'));

+ 1 - 0
packages/core/src/config/default-config.ts

@@ -86,6 +86,7 @@ export const defaultConfig: RuntimeVendureConfig = {
             origin: true,
             origin: true,
             credentials: true,
             credentials: true,
         },
         },
+        trustProxy: false,
         middleware: [],
         middleware: [],
         introspection: true,
         introspection: true,
         apolloServerPlugins: [],
         apolloServerPlugins: [],

+ 20 - 0
packages/core/src/config/vendure-config.ts

@@ -189,6 +189,14 @@ export interface ApiOptions {
      * @default []
      * @default []
      */
      */
     middleware?: Middleware[];
     middleware?: Middleware[];
+    /**
+     * @description
+     * Set the trust proxy configuration for the server. See the [express proxy docs](https://expressjs.com/en/guide/behind-proxies.html).
+     *
+     * @default false
+     * @since 3.4.0
+     */
+    trustProxy?: TrustProxyOptions;
     /**
     /**
      * @description
      * @description
      * Custom [ApolloServerPlugins](https://www.apollographql.com/docs/apollo-server/integrations/plugins/) which
      * Custom [ApolloServerPlugins](https://www.apollographql.com/docs/apollo-server/integrations/plugins/) which
@@ -222,6 +230,18 @@ export interface ApiOptions {
     introspection?: boolean;
     introspection?: boolean;
 }
 }
 
 
+/**
+ * @description
+ * Configures Express trust proxy settings when running behind a reverse proxy (usually the case with most hosting services).
+ * Setting `trustProxy` allows you to retrieve the original IP address from the `X-Forwarded-For` header.
+ *
+ * See the [express documentation](https://expressjs.com/en/guide/behind-proxies.html) for more details.
+ *
+ * @docsCategory configuration
+ * @since 3.4.0
+ */
+export type TrustProxyOptions = boolean | number | string | string[] | ((ip: string) => boolean);
+
 /**
 /**
  * @description
  * @description
  * Options for the handling of the cookies used to track sessions (only applicable if
  * Options for the handling of the cookies used to track sessions (only applicable if

+ 1 - 0
packages/create/templates/vendure-config.hbs

@@ -20,6 +20,7 @@ export const config: VendureConfig = {
         port: serverPort,
         port: serverPort,
         adminApiPath: 'admin-api',
         adminApiPath: 'admin-api',
         shopApiPath: 'shop-api',
         shopApiPath: 'shop-api',
+        trustProxy: IS_DEV ? false : 1,
         // The following options are useful in development mode,
         // The following options are useful in development mode,
         // but are best turned off for production for security
         // but are best turned off for production for security
         // reasons.
         // reasons.