Raw
1 import { TypeList } from "docs-ui"
2
3 export const metadata = {
4 title: `${pageNumber} Medusa Application Configuration`,
5 }
6
7 # {metadata.title}
8
9 In this chapter, you'll learn available configurations in the Medusa application. You can change the application's configurations to customize the behavior of the application, its integrated modules and plugins, and more.
10
11 ## Configuration File
12
13 All configurations of the Medusa application are stored in the `medusa.config.ts` file. The file exports an object created using the `defineConfig` utility. For example:
14
15 ```ts title="medusa.config.ts"
16 import { loadEnv, defineConfig } from "@medusajs/framework/utils"
17
18 loadEnv(process.env.NODE_ENV || "development", process.cwd())
19
20 module.exports = defineConfig({
21 projectConfig: {
22 databaseUrl: process.env.DATABASE_URL,
23 http: {
24 storeCors: process.env.STORE_CORS!,
25 adminCors: process.env.ADMIN_CORS!,
26 authCors: process.env.AUTH_CORS!,
27 jwtSecret: process.env.JWT_SECRET || "supersecret",
28 cookieSecret: process.env.COOKIE_SECRET || "supersecret",
29 },
30 },
31 })
32
33 ```
34
35 The `defineConfig` utility accepts an object having the following properties:
36
37 - [projectConfig](#project-configurations-projectConfig): Essential configurations related to the Medusa application, such as database and CORS configurations.
38 - [admin](#admin-configurations-admin): Configurations related to the Medusa Admin.
39 - [modules](#module-configurations-modules): Configurations related to registered modules.
40 - [plugins](#plugin-configurations-plugins): Configurations related to registered plugins.
41 - [featureFlags](#feature-flags-featureFlags): Configurations to manage enabled beta features in the Medusa application.
42 - [logger](#custom-logger-logger): Override the default logger.
43
44 ### Using Environment Variables
45
46 Notice that you use the `loadEnv` utility to load environment variables. Learn more about it in the [Environment Variables chapter](../../fundamentals/environment-variables/page.mdx).
47
48 By using this utility, you can use environment variables as the values of your configurations. It's highly recommended that you use environment variables for secret values, such as API keys and database credentials, or for values that change based on the environment, such as the application's Cross Origin Resource Sharing (CORS) configurations.
49
50 <Note title="Cloud users">
51
52 Since `medusa-config.ts` is evaluated during the build phase, any environment variable referenced in it must have the **Build** flag enabled in the [Cloud environment variables settings](!cloud!/environments/environment-variables). If a variable is only available at runtime, the configuration will read it as `undefined` during build and your module providers may fail to load.
53
54 </Note>
55
56 For example, you can set the `DATABASE_URL` environment variable in your `.env` file:
57
58 ```bash
59 DATABASE_URL=postgres://postgres@localhost/medusa-store
60 ```
61
62 Then, use the value in `medusa-config.ts`:
63
64 ```ts title="medusa-config.ts"
65 module.exports = defineConfig({
66 projectConfig: {
67 databaseUrl: process.env.DATABASE_URL,
68 // ...
69 },
70 // ...
71 })
72 ```
73
74 ---
75
76 ## Project Configurations (`projectConfig`)
77
78 The `projectConfig` object contains essential configurations related to the Medusa application, such as database and CORS configurations.
79
80 ### cookieOptions
81
82 <Note>
83
84 This option is available since Medusa [v2.8.5](https://github.com/medusajs/medusa/releases/tag/v2.8.5).
85
86 </Note>
87
88 The `projectConfig.cookieOptions` configuration defines cookie options to be passed to `express-session` when creating the session cookie. This configuration is useful when simulating a production environment locally, where you may need to set options like `secure` or `sameSite`. Learn more in the [Build chapter](../../build/page.mdx#authentication-locally-in-production-build).
89
90 #### Example
91
92 ```ts title="medusa-config.ts"
93 module.exports = defineConfig({
94 projectConfig: {
95 cookieOptions: {
96 sameSite: "lax",
97 },
98 // ...
99 },
100 // ...
101 })
102 ```
103
104 #### Properties
105
106 Aside from the following options, you can pass any property that the [express-session's cookie option accepts](https://www.npmjs.com/package/express-session).
107
108 <TypeList
109 types={[
110 {
111 name: "secure",
112 type: "`boolean`",
113 description: `Whether the cookie should only be sent over HTTPS. This is useful in production environments where you want to ensure that cookies are only sent over secure connections.`,
114 defaultValue: `false in development, true in production`
115 },
116 {
117 name: "sameSite",
118 type: "`lax` | `strict` | `none`",
119 description: `Controls the SameSite attribute of the cookie.`,
120 defaultValue: `"none" in production. In development, this attribute is not set.`
121 },
122 {
123 name: "maxAge",
124 type: "`number`",
125 description: "The maximum age of the cookie in milliseconds set in the `Set-Cookie` header.",
126 defaultValue: "Either the `sessionOptions.ttl` option, or `10` hours."
127 },
128 {
129 name: "httpOnly",
130 type: "`boolean`",
131 description: "Whether to set the `HttpOnly Set-Cookie` attribute.",
132 defaultValue: `true`
133 },
134 {
135 name: "priority",
136 type: "`low` \| `medium` \| `high`",
137 description: "The value of the [Priority Set-Cookie attribute](https://tools.ietf.org/html/draft-west-cookie-priority-00#section-4.1)",
138 defaultValue: `medium`
139 },
140 {
141 name: "domain",
142 type: "`string`",
143 description: "The value of the `Domain Set-Cookie` attribute. By default, no domain is set, and most clients will consider the cookie to apply to the current domain only."
144 },
145 {
146 name: "path",
147 type: "`string`",
148 description: "The value of the `Path Set-Cookie` attribute",
149 defaultValue: `/`
150 },
151 {
152 name: "signed",
153 type: "`boolean`",
154 description: "Whether to sign the cookie.",
155 defaultValue: `true`
156 }
157 ]}
158 openedLevel={1}
159 />
160
161 ### databaseDriverOptions
162
163 The `projectConfig.databaseDriverOptions` configuration is an object of additional options used to configure the PostgreSQL connection. For example, you can support TLS/SSL connection using this configuration's `ssl` property.
164
165 This configuration is useful for production databases, which can be supported by setting the `rejectUnauthorized` attribute of `ssl` object to `false`. During development, it's recommended not to pass the `ssl.rejectUnauthorized` option.
166
167 <Note type="warning">
168
169 Do not set this option when deploying to [Cloud](!cloud!/projects/prerequisites). Cloud automatically manages the database connection and SSL configuration. Setting it manually may cause deployment or database migration failures.
170
171 </Note>
172
173 #### Example
174
175 ```ts title="medusa-config.ts"
176 module.exports = defineConfig({
177 projectConfig: {
178 databaseDriverOptions: process.env.NODE_ENV !== "development" ?
179 { connection: { ssl: { rejectUnauthorized: false } } } : {},
180 // ...
181 },
182 // ...
183 })
184 ```
185
186 <Note title="Tip">
187
188 When you disable `rejectUnauthorized`, make sure to also add `?ssl_mode=disable` to the end of the [databaseUrl](#databaseUrl) as well.
189
190 </Note>
191
192 #### AWS RDS IAM Database Authentication
193
194 To use a dynamic password (for example, with AWS RDS IAM authentication), pass a `dynamicPassword` function that returns a fresh token for each new connection:
195
196 <Note>
197
198 This option is available since Medusa [v2.18.0](https://github.com/medusajs/medusa/releases/tag/v2.18.0)
199
200 </Note>
201
202 ```ts title="medusa-config.ts"
203 import { generateAuthToken } from "./src/utils/rds-auth"
204
205 module.exports = defineConfig({
206 projectConfig: {
207 databaseDriverOptions: {
208 dynamicPassword: async () => generateAuthToken(),
209 expirationChecker: () => {
210 return tokenHasExpired()
211 },
212 },
213 // ...
214 },
215 // ...
216 })
217 ```
218
219 #### Properties
220
221 <TypeList
222 types={[
223 {
224 name: "connection",
225 type: "`object`",
226 description: `An object of connection options.`,
227 children: [
228 {
229 name: "ssl",
230 type: "`object` \| `boolean`",
231 description: `Either a boolean indicating whether to use SSL or an object of SSL options. You can find the full list of options in the [Node.js documentation](https://nodejs.org/docs/latest-v20.x/api/tls.html#tlsconnectoptions-callback).`,
232 defaultValue: `false`,
233 children: [
234 {
235 name: "rejectUnauthorized",
236 type: `boolean`,
237 description: `Whether to reject unauthorized connections.`,
238 defaultValue: `true`
239 }
240 ]
241 },
242 {
243 name: "pool",
244 type: "`object`",
245 description: `An object of options initialized by the underlying [knex](https://knexjs.org/guide/#pool) client.`,
246 children: [
247 {
248 name: "min",
249 type: "`number`",
250 description: `The minimum number of connections in the pool.`,
251 defaultValue: `1`
252 },
253 {
254 name: "max",
255 type: "`number`",
256 description: `The maximum number of connections in the pool.`,
257 defaultValue: `10`
258 },
259 {
260 name: "idleTimeoutMillis",
261 type: "`number`",
262 description: `The maximum time, in milliseconds, that a connection can be idle before being released.`,
263 defaultValue: `30000`
264 },
265 {
266 name: "reapIntervalMillis",
267 type: "`number`",
268 description: `How often to check for idle connections that can be released.`,
269 defaultValue: `1000`
270 },
271 {
272 name: "createRetryIntervalMillis",
273 type: "`number`",
274 description: `How long to wait before retrying to create a connection after a failure.`,
275 defaultValue: `200`
276 }
277 ]
278 }
279 ]
280 },
281 {
282 name: "dynamicPassword",
283 type: "`() => string` \| `() => Promise<string>`",
284 description: `A function that returns a password (or a promise resolving to a password) called for each new database connection. Use this for short-lived credentials, such as AWS RDS IAM authentication tokens, that must be refreshed per connection. Available since v2.18.0.`
285 },
286 {
287 name: "expirationChecker",
288 type: "`() => boolean`",
289 description: `A function that returns \`true\` when a connection's credentials have expired. When this returns \`true\`, the connection pool creates a new connection and calls \`dynamicPassword\` to obtain fresh credentials. Available since v2.18.0.`
290 },
291 {
292 name: "idle_in_transaction_session_timeout",
293 type: "`number`",
294 description: `The maximum time, in milliseconds, that a session can be idle before being terminated.`,
295 defaultValue: `60000`
296 }
297 ]}
298 openedLevel={1}
299 sectionTitle="databaseDriverOptions Properties"
300 />
301
302 ### databaseLogging
303
304 The `projectConfig.databaseLogging` configuration specifies whether database messages should be logged to the console. It is `false` by default.
305
306 #### Example
307
308 ```ts title="medusa-config.ts"
309 module.exports = defineConfig({
310 projectConfig: {
311 databaseLogging: true,
312 // ...
313 },
314 // ...
315 })
316 ```
317
318 ### databaseName
319
320 The `projectConfig.databaseName` configuration determines the name of the database to connect to. If the name is specified in the [databaseUrl](#databaseUrl) configuration, you don't have to use this configuration.
321
322 <Note title="Tip">
323
324 After setting the database credentials, you can create and setup the database using the [db:setup](!resources!/medusa-cli/commands/db#dbsetup) command of the Medusa CLI.
325
326 </Note>
327
328 #### Example
329
330 ```ts title="medusa-config.ts"
331 module.exports = defineConfig({
332 projectConfig: {
333 databaseName: process.env.DATABASE_NAME ||
334 "medusa-store",
335 // ...
336 },
337 // ...
338 })
339 ```
340
341 ### databaseUrl
342
343 The `projectConfig.databaseUrl` configuration specifies the PostgreSQL connection URL of the database to connect to. Its format is:
344
345 ```bash
346 postgres://[user][:password]@[host][:port]/[dbname]
347 ```
348
349 Where:
350
351 - `[user]`: (required) your PostgreSQL username. If not specified, the system's username is used by default. The database user that you use must have create privileges. If you're using the `postgres` superuser, then it should have these privileges by default. Otherwise, make sure to grant your user create privileges. You can learn how to do that in [PostgreSQL's documentation](https://www.postgresql.org/docs/current/ddl-priv.html).
352 - `[:password]`: an optional password for the user. When provided, make sure to put `:` before the password.
353 - `[host]`: (required) your PostgreSQL host. When run locally, it should be `localhost`.
354 - `[:port]`: an optional port that the PostgreSQL server is listening on. By default, it's `5432`. When provided, make sure to put `:` before the port.
355 - `[dbname]`: the name of the database. If not set, then you must provide the database name in the [databaseName](#databasename) configuration.
356
357 You can learn more about the connection URL format in [PostgreSQL’s documentation](https://www.postgresql.org/docs/current/libpq-connect.html).
358
359 <Note title="Tip">
360
361 After setting the database URL, you can create and setup the database using the [db:setup](!resources!/medusa-cli/commands/db#dbsetup) command of the Medusa CLI.
362
363 </Note>
364
365 #### Example
366
367 For example, set the following database URL in your environment variables:
368
369 ```bash
370 DATABASE_URL=postgres://postgres@localhost/medusa-store
371 ```
372
373 Then, use the value in `medusa-config.ts`:
374
375 ```ts title="medusa-config.ts"
376 module.exports = defineConfig({
377 projectConfig: {
378 databaseUrl: process.env.DATABASE_URL,
379 // ...
380 },
381 // ...
382 })
383 ```
384
385 ### http
386
387 The `http` configures the application's http-specific settings, such as the JWT secret, CORS configurations, and more.
388
389 #### http.jwtOptions
390
391 The `projectConfig.http.jwtOptions` configuration specifies options for the JWT token when using asymmetric signing private/public key. These options will be used for validation if `jwtVerifyOptions` is not provided.
392
393 This configuration accepts an object with the same properties as the [jsonwebtoken sign options](https://www.npmjs.com/package/jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback).
394
395 <Note>
396
397 Learn more in the [Asymmetric Encryption chapter](./asymmetric-encryption/page.mdx).
398
399 </Note>
400
401 #### Example
402
403 ```ts title="medusa-config.ts"
404 module.exports = defineConfig({
405 projectConfig: {
406 http: {
407 jwtOptions: {
408 algorithm: "RS256",
409 expiresIn: "1h",
410 issuer: "medusa",
411 keyid: "medusa",
412 },
413 },
414 // ...
415 },
416 // ...
417 })
418 ```
419
420 #### http.jwtPublicKey
421
422 The `projectConfig.http.jwtPublicKey` configuration specifies the public key used to verify the JWT token in combination with the JWT secret and the JWT options. This is only used when the JWT secret is a secret key for asymmetric validation.
423
424 It accepts one of the following values:
425
426 - A string containing the public key in PEM format.
427 - A `Buffer` containing the public key in PEM format.
428 - An object containing the following properties:
429 - `key`: A string or `Buffer` containing the public key in PEM format.
430 - `passphrase`: A string containing the passphrase for the public key, if applicable.
431
432 <Note>
433
434 Learn more in the [Asymmetric Encryption chapter](./asymmetric-encryption/page.mdx).
435
436 </Note>
437
438 #### Example
439
440 ```ts title="medusa-config.ts"
441 module.exports = defineConfig({
442 projectConfig: {
443 http: {
444 jwtPublicKey: process.env.JWT_PUBLIC_KEY,
445 },
446 // ...
447 },
448 // ...
449 })
450 ```
451
452 #### http.jwtSecret
453
454 The `projectConfig.http.jwtSecret` configuration is a random string used to create authentication tokens in the HTTP layer. This configuration is not required in development, but must be set in production.
455
456 In a development environment, if this option is not set the default value is `supersecret`. However, in production, if this configuration is not set, an error is thrown and the application crashes. This is to ensure that you set a secure value for the JWT secret in production.
457
458 #### Example
459
460 ```ts title="medusa-config.ts"
461 module.exports = defineConfig({
462 projectConfig: {
463 http: {
464 jwtSecret: process.env.JWT_SECRET || "supersecret",
465 },
466 // ...
467 },
468 // ...
469 })
470 ```
471
472 #### http.jwtVerifyOptions
473
474 The `projectConfig.http.jwtVerifyOptions` configuration specifies options for the JWT token when using asymmetric validation private/public key.
475
476 This configuration accepts the same options as the [jsonwebtoken verify options](https://www.npmjs.com/package/jsonwebtoken#jwtverifytoken-secretorpublickey-options-callback).
477
478 <Note>
479
480 Learn more in the [Asymmetric Encryption chapter](./asymmetric-encryption/page.mdx).
481
482 </Note>
483
484 #### Example
485
486 ```ts title="medusa-config.ts"
487 module.exports = defineConfig({
488 projectConfig: {
489 http: {
490 jwtVerifyOptions: {
491 algorithms: ["RS256"],
492 issuer: "medusa",
493 },
494 },
495 // ...
496 },
497 // ...
498 })
499 ```
500
501 #### http.jwtExpiresIn
502
503 The `projectConfig.http.jwtExpiresIn` configuration specifies the expiration time for the JWT token. Its value format is based off the [ms package](https://github.com/vercel/ms).
504
505 If not provided, the default value is `1d`.
506
507 #### Example
508
509 ```ts title="medusa-config.ts"
510 module.exports = defineConfig({
511 projectConfig: {
512 http: {
513 jwtExpiresIn: process.env.JWT_EXPIRES_IN || "2d",
514 },
515 // ...
516 },
517 // ...
518 })
519 ```
520
521 #### http.cookieSecret
522
523 The `projectConfig.http.cookieSecret` configuration is a random string used to sign cookies in the HTTP layer. This configuration is not required in development, but must be set in production.
524
525 In a development environment, if this option is not set the default value is `supersecret`. However, in production, if this configuration is not set, an error is thrown and the application crashes. This is to ensure that you set a secure value for the cookie secret in production.
526
527 #### Example
528
529 ```ts title="medusa-config.ts"
530 module.exports = defineConfig({
531 projectConfig: {
532 http: {
533 cookieSecret: process.env.COOKIE_SECRET || "supersecret",
534 },
535 // ...
536 },
537 // ...
538 })
539 ```
540
541 #### http.authCors
542
543 The `projectConfig.http.authCors` configuration specifies the accepted URLs or patterns for API routes starting with `/auth`. It can either be one accepted origin, or a comma-separated list of accepted origins.
544
545 Every origin in that list must either be:
546
547 - A full URL. For example, `http://localhost:7001`. The URL must not end with a backslash;
548 - Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that Medusa tests for is `^([\/~@;%#'])(.*?)\1([gimsuy]*)$`.
549
550 Since the `/auth` routes are used for authentication for both store and admin routes, it's recommended to set this configuration's value to a combination of the [storeCors](#httpstoreCors) and [adminCors](#httpadminCors) configurations.
551
552 Some example values of common use cases:
553
554 ```bash
555 # Allow different ports locally starting with 700
556 AUTH_CORS=/http:\/\/localhost:700\d+$/
557
558 # Allow any origin ending with vercel.app. For example, admin.vercel.app
559 AUTH_CORS=/vercel\.app$/
560
561 # Allow all HTTP requests
562 AUTH_CORS=/http:\/\/.+/
563 ```
564
565 Then, set the configuration in `medusa-config.ts`:
566
567 ```ts title="medusa-config.ts"
568 module.exports = defineConfig({
569 projectConfig: {
570 http: {
571 authCors: process.env.AUTH_CORS,
572 },
573 // ...
574 },
575 // ...
576 })
577 ```
578
579 If you’re adding the value directly within `medusa-config.ts`, make sure to add an extra escaping `/` for every backslash in the pattern. For example:
580
581 ```ts title="medusa-config.ts"
582 module.exports = defineConfig({
583 projectConfig: {
584 http: {
585 authCors: "/http:\\/\\/localhost:700\\d+$/",
586 },
587 // ...
588 },
589 // ...
590 })
591 ```
592
593 #### http.storeCors
594
595 The `projectConfig.http.storeCors` configuration specifies the accepted URLs or patterns for API routes starting with `/store`. It can either be one accepted origin, or a comma-separated list of accepted origins.
596
597 Every origin in that list must either be:
598
599 - A full URL. For example, `http://localhost:7001`. The URL must not end with a backslash;
600 - Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that Medusa tests for is `^([\/~@;%#'])(.*?)\1([gimsuy]*)$`.
601
602 Some example values of common use cases:
603
604 ```bash
605 # Allow different ports locally starting with 800
606 STORE_CORS=/http:\/\/localhost:800\d+$/
607
608 # Allow any origin ending with vercel.app. For example, storefront.vercel.app
609 STORE_CORS=/vercel\.app$/
610
611 # Allow all HTTP requests
612 STORE_CORS=/http:\/\/.+/
613 ```
614
615 Then, set the configuration in `medusa-config.ts`:
616
617 ```ts title="medusa-config.ts"
618 module.exports = defineConfig({
619 projectConfig: {
620 http: {
621 storeCors: process.env.STORE_CORS,
622 },
623 // ...
624 },
625 // ...
626 })
627 ```
628
629 If you’re adding the value directly within `medusa-config.ts`, make sure to add an extra escaping `/` for every backslash in the pattern. For example:
630
631 ```ts title="medusa-config.ts"
632 module.exports = defineConfig({
633 projectConfig: {
634 http: {
635 storeCors: "/vercel\\.app$/",
636 },
637 // ...
638 },
639 // ...
640 })
641 ```
642
643 #### http.adminCors
644
645 The `projectConfig.http.adminCors` configuration specifies the accepted URLs or patterns for API routes starting with `/admin`. It can either be one accepted origin, or a comma-separated list of accepted origins.
646
647 Every origin in that list must either be:
648
649 - A full URL. For example, `http://localhost:7001`. The URL must not end with a backslash;
650 - Or a regular expression pattern that can match more than one origin. For example, `.example.com`. The regex pattern that Medusa tests for is `^([\/~@;%#'])(.*?)\1([gimsuy]*)$`.
651
652 Some example values of common use cases:
653
654 ```bash
655 # Allow different ports locally starting with 700
656 ADMIN_CORS=/http:\/\/localhost:700\d+$/
657
658 # Allow any origin ending with vercel.app. For example, admin.vercel.app
659 ADMIN_CORS=/vercel\.app$/
660
661 # Allow all HTTP requests
662 ADMIN_CORS=/http:\/\/.+/
663 ```
664
665 Then, set the configuration in `medusa-config.ts`:
666
667 ```ts title="medusa-config.ts"
668 module.exports = defineConfig({
669 projectConfig: {
670 http: {
671 adminCors: process.env.ADMIN_CORS,
672 },
673 // ...
674 },
675 // ...
676 })
677 ```
678
679 If you’re adding the value directly within `medusa-config.ts`, make sure to add an extra escaping `/` for every backslash in the pattern. For example:
680
681 ```ts title="medusa-config.ts"
682 module.exports = defineConfig({
683 projectConfig: {
684 http: {
685 adminCors: "/vercel\\.app$/",
686 },
687 // ...
688 },
689 // ...
690 })
691 ```
692
693 #### http.authVerificationsPerActor
694
695 <Note>
696
697 This option is available since Medusa [v2.16.0](https://github.com/medusajs/medusa/releases/tag/v2.16.0).
698
699 </Note>
700
701 The `projectConfig.http.authVerificationsPerActor` configuration specifies the required verification methods per actor type (such as `user`, `customer`, or any custom actor). This configuration is useful to enforce email verification or other verification methods for specific actor types.
702
703 For example:
704
705 ```ts title="medusa-config.ts"
706 module.exports = defineConfig({
707 projectConfig: {
708 http: {
709 authVerificationsPerActor: {
710 user: [], // No verification required for users
711 customer: [
712 {
713 entity_type: "email",
714 auth_provider: "emailpass",
715 },
716 ],
717 },
718 },
719 // ...
720 },
721 // ...
722 })
723 ```
724
725 The configuration accepts an object whose key is the actor type (for example, `user` for admin user, `customer` for customer, or any custom actor type), and the value is an array of objects having the following properties:
726
727 <TypeList
728 types={[
729 {
730 name: "entity_type",
731 type: "`string`",
732 description: `The type of entity to verify. For example, "email" for email verification.`,
733 },
734 {
735 name: "auth_provider",
736 type: "`string`",
737 description: `The auth provider ID that the verification is associated with. For example, "emailpass" for email/password authentication.`,
738 }
739 ]}
740 sectionTitle="authVerificationsPerActor Properties"
741 />
742
743 #### http.compression
744
745 The `projectConfig.http.compression` configuration modifies the HTTP compression settings at the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there. However, some platforms don't offer access to the HTTP layer and in those cases, this is a good alternative.
746
747 If you enable HTTP compression and you want to disable it for specific API Routes, you can pass in the request header `"x-no-compression": true`. Learn more in the [API Reference](https://docs.medusajs.com/api/store/http-compression).
748
749 For example:
750
751 ```ts title="medusa-config.ts"
752 module.exports = defineConfig({
753 projectConfig: {
754 http: {
755 compression: {
756 enabled: true,
757 level: 6,
758 memLevel: 8,
759 threshold: 1024,
760 },
761 },
762 // ...
763 },
764 // ...
765 })
766 ```
767
768 This configuration is an object that accepts the following properties:
769
770 <TypeList
771 types={[
772 {
773 name: "enabled",
774 type: "`boolean`",
775 description: `Whether to enable HTTP compression.`,
776 defaultValue: `false`
777 },
778 {
779 name: "level",
780 type: "`number`",
781 description: "The level of zlib compression to apply to responses. A higher level will result in better compression but will take longer to complete. A lower level will result in less compression but will be much faster.",
782 defaultValue: `6`
783 },
784 {
785 name: "memLevel",
786 type: "`number`",
787 description: "How much memory should be allocated to the internal compression state. It value is between `1` (minimum level) and `9` (maximum level).",
788 defaultValue: `8`
789 },
790 {
791 name: "threshold",
792 type: "`number` \| `string`",
793 description: "The minimum response body size that compression is applied on. Its value can be the number of bytes or any string accepted by the [bytes](https://www.npmjs.com/package/bytes) package.",
794 defaultValue: `1024`
795 }
796 ]}
797 sectionTitle="http.compression Properties"
798 />
799
800 #### http.authMethodsPerActor
801
802 The `projectConfig.http.authMethodsPerActor` configuration specifies the supported authentication providers per actor type (such as `user`, `customer`, or any custom actor).
803
804 For example, you can allow Google login for `customers`, and allow email/password logins for `users` in the admin.
805
806 `authMethodsPerActor` is a an object whose key is the actor type (for example, `user`), and the value is an array of supported auth provider IDs (for example, `emailpass`).
807
808 <Note>
809
810 Learn more about actor types in the [Auth Identity and Actor Type documentation](!resources!/commerce-modules/auth/auth-identity-and-actor-types).
811
812 </Note>
813
814 By default, the `user` actor type is restricted to the `emailpass` provider. All other actor types (for example, `customer`) can authenticate with any installed auth provider unless you explicitly restrict them with this configuration.
815
816 For example:
817
818 ```ts title="medusa-config.ts"
819 module.exports = defineConfig({
820 projectConfig: {
821 http: {
822 authMethodsPerActor: {
823 user: ["emailpass"],
824 customer: ["emailpass", "google"],
825 },
826 },
827 // ...
828 },
829 // ...
830 })
831 ```
832
833 The above configurations allow admin users to login using email/password, and customers to login using email/password and Google.
834
835 #### http.restrictedFields
836
837 The `projectConfig.http.restrictedFields` configuration specifies the fields that can't be selected in API routes (using the `fields` query parameter) unless they're allowed in the [request's Query configurations](../../fundamentals/query/page.mdx#request-query-configurations). This is useful to restrict sensitive fields from being exposed in the API.
838
839 For example, you can restrict selecting customers in store API routes:
840
841 ```ts title="medusa-config.ts"
842 module.exports = defineConfig({
843 projectConfig: {
844 http: {
845 restrictedFields: {
846 store: ["customer", "customers"],
847 },
848 },
849 // ...
850 },
851 // ...
852 })
853 ```
854
855 The `restrictedFields` configuration accepts the following properties:
856
857 <TypeList
858 types={[
859 {
860 name: "store",
861 type: "`string[]`",
862 description: `An array of fields that can't be selected in store API routes.`,
863 defaultValue: `["order", "orders"]`
864 }
865 ]}
866 sectionTitle="http.restrictedFields Properties"
867 />
868
869 #### http.storeRelationsLimit
870
871 <Note>
872
873 This configuration is available since Medusa [v2.20.0](https://github.com/medusajs/medusa/releases/tag/v2.20.0).
874
875 </Note>
876
877 The `projectConfig.http.storeRelationsLimit` configuration sets the maximum number of relations a caller can expand in a single request to a Store API route. For example, requesting `variants.options.values` expands three relations.
878
879 The default value is `3`. Individual routes can override this limit through their query configuration's `storeRelationsLimit` property.
880
881 ```ts title="medusa-config.ts"
882 module.exports = defineConfig({
883 projectConfig: {
884 http: {
885 storeRelationsLimit: 4,
886 },
887 // ...
888 },
889 // ...
890 })
891 ```
892
893 ---
894
895 ### redisOptions
896
897 The `projectConfig.redisOptions` configuration defines options to pass to `ioredis`, which creates the Redis connection used to store the Medusa server session. Refer to [ioredis's RedisOptions documentation](https://redis.github.io/ioredis/index.html#RedisOptions)
898 for the list of available options.
899
900 #### Example
901
902 ```ts title="medusa-config.ts"
903 module.exports = defineConfig({
904 projectConfig: {
905 redisOptions: {
906 connectionName: process.env.REDIS_CONNECTION_NAME ||
907 "medusa",
908 },
909 // ...
910 },
911 // ...
912 })
913 ```
914
915 ### redisPrefix
916
917 The `projectConfig.redisPrefix` configuration defines a prefix on all keys stored in Redis for the Medusa server session. The default value is `sess:`.
918
919 The value of this configuration is prepended to `sess:`. For example, if you set it to `medusa:`, then a key stored in Redis is prefixed by `medusa:sess`.
920
921 <Note>
922
923 This configuration is not used for modules that also connect to Redis, such as the [Redis Caching Module Provider](!resources!/infrastructure-modules/caching/providers/redis).
924
925 </Note>
926
927 #### Example
928
929 ```ts title="medusa-config.ts"
930 module.exports = defineConfig({
931 projectConfig: {
932 redisPrefix: process.env.REDIS_URL || "medusa:",
933 // ...
934 },
935 // ...
936 })
937 ```
938
939 ### redisUrl
940
941 The `projectConfig.redisUrl` configuration specifies the connection URL to Redis to store the Medusa server session. When specified, the Medusa server uses Redis to store the session data. Otherwise, the session data is stored in-memory.
942
943 This configuration is not used for modules that also connect to Redis, such as the [Redis Caching Module Provider](!resources!/infrastructure-modules/caching/providers/redis). You'll have to configure the Redis connection for those modules separately.
944
945 <Note type="warning">
946
947 Do not set this option when deploying to [Cloud](!cloud!/projects/prerequisites). Cloud automatically manages Redis provisioning. Setting it manually may cause deployment failures.
948
949 </Note>
950
951 <Note>
952
953 You must first have Redis installed. You can refer to [Redis's installation guide](https://redis.io/docs/getting-started/installation/).
954
955 </Note>
956
957 The Redis connection URL has the following format:
958
959 ```bash
960 redis[s]://[[username][:password]@][host][:port][/db-number]
961 ```
962
963 Where:
964
965 - `redis[s]`: the protocol used to connect to Redis. Use `rediss` for a secure connection.
966 - `[[username][:password]@]`: an optional username and password for the Redis server.
967 - `[host]`: the host of the Redis server. When run locally, it should be `localhost`.
968 - `[:port]`: an optional port that the Redis server is listening on. By default, it's `6379`.
969 - `[/db-number]`: an optional database number to connect to. By default, it's `0`.
970
971 For a local Redis installation, the connection URL should be `redis://localhost:6379` unless you’ve made any changes to the Redis configuration during installation.
972
973 #### Example
974
975 ```ts title="medusa-config.ts"
976 module.exports = defineConfig({
977 projectConfig: {
978 redisUrl: process.env.REDIS_URL ||
979 "redis://localhost:6379",
980 // ...
981 },
982 // ...
983 })
984 ```
985
986 ### sessionOptions
987
988 The `projectConfig.sessionOptions` configuration defines additional options to pass to [express-session](https://www.npmjs.com/package/express-session), which is used to store the Medusa server session.
989
990 <Note>
991
992 This configuration is not used for modules that also connect to Redis, such as the [Redis Caching Module Provider](!resources!/infrastructure-modules/caching/providers/redis).
993
994 </Note>
995
996 #### Example
997
998 ```ts title="medusa-config.ts"
999 module.exports = defineConfig({
1000 projectConfig: {
1001 sessionOptions: {
1002 name: process.env.SESSION_NAME || "custom",
1003 },
1004 // ...
1005 },
1006 // ...
1007 })
1008 ```
1009
1010 #### Properties
1011
1012 <TypeList
1013 types={[
1014 {
1015 name: "name",
1016 type: "`string`",
1017 description: `The name of the session ID cookie to set in the response (and read from in the request). Refer to [express-session’s documentation](https://www.npmjs.com/package/express-session#name) for more details.`,
1018 defaultValue: "`connect.sid`"
1019 },
1020 {
1021 name: "resave",
1022 type: "`boolean`",
1023 description: `Whether the session should be saved back to the session store, even if the session was never modified during the request. Refer to [express-session’s documentation](https://www.npmjs.com/package/express-session#resave) for more details.`,
1024 defaultValue: `true`
1025 },
1026 {
1027 name: "rolling",
1028 type: "`boolean`",
1029 description: `Whether the session identifier cookie should be force-set on every response. Refer to [express-session’s documentation](https://www.npmjs.com/package/express-session#rolling) for more details.`,
1030 defaultValue: `false`
1031 },
1032 {
1033 name: "saveUninitialized",
1034 type: "`boolean`",
1035 description: `Whether to save sessions that are new but not modified. Refer to [express-session’s documentation](https://www.npmjs.com/package/express-session#saveUninitialized) for more details.`,
1036 defaultValue: `true`
1037 },
1038 {
1039 name: "secret",
1040 type: "`string`",
1041 description: "The secret to sign the session ID cookie. By default, the value of [http.cookieSecret](#httpcookieSecret) is used. Refer to [express-session’s documentation](https://www.npmjs.com/package/express-session#secret) for details."
1042 },
1043 {
1044 name: "ttl",
1045 type: "`number`",
1046 description: "The time-to-live (TTL) of the session ID cookie in milliseconds. It is used when calculating the `Expires` `Set-Cookie` attribute of cookies. Refer to [express-session’s documentation](https://www.npmjs.com/package/express-session#cookie) for more details.",
1047 defaultValue: `36000000`
1048 }
1049 ]}
1050 sectionTitle="sessionOptions Properties"
1051 />
1052
1053 ### workerMode
1054
1055 The `projectConfig.workerMode` configuration specifies the worker mode of the Medusa application. You can learn more about it in the [Worker Mode chapter](../../production/worker-mode/page.mdx).
1056
1057 The value for this configuration can be one of the following:
1058
1059 - `shared`: run the application in a single process, meaning the worker and server run in the same process.
1060 - `worker`: run the a worker process only.
1061 - `server`: run the application server only.
1062
1063 #### Example
1064
1065 ```ts title="medusa-config.ts"
1066 module.exports = defineConfig({
1067 projectConfig: {
1068 workerMode: process.env.WORKER_MODE as "shared" | "worker" | "server" || "shared",
1069 // ...
1070 },
1071 // ...
1072 })
1073 ```
1074
1075 ---
1076
1077 ## Admin Configurations (`admin`)
1078
1079 The `admin` object contains configurations related to the Medusa Admin.
1080
1081 ### backendUrl
1082
1083 The `admin.backendUrl` configuration specifies the URL of the Medusa application. Its default value is the browser origin. This is useful to set when running the admin on a separate domain.
1084
1085 #### Example
1086
1087 ```ts title="medusa-config.ts"
1088 module.exports = defineConfig({
1089 admin: {
1090 backendUrl: process.env.MEDUSA_BACKEND_URL ||
1091 "http://localhost:9000",
1092 },
1093 // ...
1094 })
1095 ```
1096
1097 ### disable
1098
1099 The `admin.disable` configuration specifies whether to disable the Medusa Admin. If disabled, the Medusa Admin will not be compiled and you can't access it at `/app` path of your application. The default value is `false`.
1100
1101 #### Example
1102
1103 ```ts title="medusa-config.ts"
1104 module.exports = defineConfig({
1105 admin: {
1106 disable: process.env.ADMIN_DISABLED === "true" ||
1107 false,
1108 },
1109 // ...
1110 })
1111 ```
1112
1113 ### path
1114
1115 The `admin.path` configuration indicates the path to the admin dashboard, which is `/app` by default. The value must start with `/` and can't end with a `/`.
1116
1117 The value cannot be one of the reserved paths:
1118 - `/admin`
1119 - `/store`
1120 - `/auth`
1121
1122 <Note>
1123
1124 When using Docker, make sure that the root path of the Docker image isn't the same as the admin's path. For example, if the Docker image's root path is `/app`, change
1125 the value of the `admin.path` configuration, since it's `/app` by default.
1126
1127 </Note>
1128
1129 #### Example
1130
1131 ```ts title="medusa-config.ts"
1132 module.exports = defineConfig({
1133 admin: {
1134 path: process.env.ADMIN_PATH || `/app`,
1135 },
1136 // ...
1137 })
1138 ```
1139
1140 ### storefrontUrl
1141
1142 The `admin.storefrontUrl` configuration specifies the URL of the Medusa storefront application. This URL is used as a prefix to some links in the admin that require performing actions in the storefront.
1143
1144 For example, this URL is used as a prefix to shareable payment links for orders with outstanding amounts.
1145
1146 #### Example
1147
1148 ```js title="medusa-config.js"
1149 module.exports = defineConfig({
1150 admin: {
1151 storefrontUrl: process.env.MEDUSA_STOREFRONT_URL ||
1152 "http://localhost:8000",
1153 },
1154 // ...
1155 })
1156 ```
1157
1158 ### vite
1159
1160 The `admin.vite` configuration specifies Vite configurations for the Medusa Admin. Its value is a function that receives the default Vite configuration and returns the modified configuration. The default value is `undefined`.
1161
1162 Learn about configurations you can pass to Vite in [Vite's documentation](https://vite.dev/config/).
1163
1164 <Note>
1165
1166 Starting from [Medusa v2.19.0](https://github.com/medusajs/medusa/releases/tag/v2.19.0), the function receives a Vite v7 configuration object, whereas it received a Vite v5 configuration object in earlier versions. So, if you set `build.target` to `modules`, or use the removed `splitVendorChunkPlugin`, update your configuration. Also, if you installed `vite` in your project for type support, update it to v7.
1167
1168 </Note>
1169
1170 #### Example
1171
1172 For example, if you're using a third-party library that isn't ESM-compatible, add it to Vite's `optimizeDeps` configuration:
1173
1174 ```ts title="medusa-config.ts"
1175 module.exports = defineConfig({
1176 admin: {
1177 vite: (config) => {
1178 return {
1179 ...config,
1180 optimizeDeps: {
1181 include: ["qs"],
1182 },
1183 }
1184 },
1185 },
1186 // ...
1187 })
1188 ```
1189
1190 ---
1191
1192 ## Module Configurations (`modules`)
1193
1194 The `modules` configuration allows you to register and configure the [modules](../../fundamentals/modules/page.mdx) registered in the Medusa application. Medusa's commerce and Infrastructure Modules are configured by default. So, you only need to pass your custom modules, or override the default configurations of the existing modules.
1195
1196 `modules` is an array of objects for the modules to register. Each object has the following properties:
1197
1198 1. `resolve`: a string indicating the path to the module, or the module's NPM package name. For example, `./src/modules/my-module`.
1199 2. `options`: (optional) an object indicating the [options to pass to the module](../../fundamentals/modules/options/page.mdx). This object is specific to the module and its configurations. For example, your module may require an API key option, which you can pass in this object.
1200
1201 <Note>
1202
1203 For modules that are part of a plugin, learn about registering them in the [Register Modules in Plugins](#register-modules-in-plugins) section.
1204
1205 </Note>
1206
1207 ### Example
1208
1209 To register a custom module:
1210
1211 <Note title="Cloud users">
1212
1213 Environment variables used in module `options` are read during the build phase. When deploying to Cloud, make sure each variable has the **Build** flag enabled in your [environment variables settings](!cloud!/environments/environment-variables). A variable that is only enabled at runtime will be `undefined` when the module loads, causing errors such as "Option `apiKey` is required".
1214
1215 </Note>
1216
1217 ```ts title="medusa-config.ts"
1218 module.exports = defineConfig({
1219 modules: [
1220 {
1221 resolve: "./src/modules/cms",
1222 options: {
1223 apiKey: process.env.CMS_API_KEY,
1224 },
1225 },
1226 ],
1227 // ...
1228 })
1229 ```
1230
1231 You can also override the default configurations of Medusa's modules. For example, to add a Notification Module Provider to the Notification Module:
1232
1233 ```ts title="medusa-config.ts"
1234 module.exports = defineConfig({
1235 modules: [
1236 {
1237 resolve: "@medusajs/medusa/notification",
1238 options: {
1239 providers: [
1240 // default provider
1241 {
1242 resolve: "@medusajs/medusa/notification-local",
1243 id: "local",
1244 options: {
1245 name: "Local Notification Provider",
1246 channels: ["feed"],
1247 },
1248 },
1249 // custom provider
1250 {
1251 resolve: "./src/modules/my-notification",
1252 id: "my-notification",
1253 options: {
1254 channels: ["email"],
1255 // provider options...
1256 },
1257 },
1258 ],
1259 },
1260 },
1261 ],
1262 // ...
1263 })
1264 ```
1265
1266 ---
1267
1268 ## Plugin Configurations (`plugins`)
1269
1270 The `plugins` configuration allows you to register and configure the [plugins](../../fundamentals/plugins/page.mdx) registered in the Medusa application. Plugins include re-usable Medusa customizations, such as modules, workflows, API routes, and more.
1271
1272 Aside from installing the plugin with NPM, you must also register it in the `medusa.config.ts` file.
1273
1274 The `plugins` configuration is an array of objects for the plugins to register. Each object has the following properties:
1275
1276 - A string, which is the name of the plugin's package as specified in the plugin's `package.json` file. This is useful if the plugin doesn't require any options.
1277 - An object having the following properties:
1278 - `resolve`: The name of the plugin's package as specified in the plugin's `package.json` file.
1279 - `options`: An object that includes [options to be passed to the modules](../../fundamentals/modules/options/page.mdx#pass-options-to-a-module-in-a-plugin) within the plugin.
1280
1281 ### Example
1282
1283 ```ts title="medusa-config.ts"
1284 module.exports = {
1285 plugins: [
1286 `medusa-my-plugin-1`,
1287 {
1288 resolve: `medusa-my-plugin`,
1289 options: {
1290 apiKey: process.env.MY_API_KEY ||
1291 `test`,
1292 },
1293 },
1294 // ...
1295 ],
1296 // ...
1297 }
1298 ```
1299
1300 The above configuration registers two plugins: `medusa-my-plugin-1` and `medusa-my-plugin`. The latter plugin requires an API key option, which is passed in the `options` object.
1301
1302 ### Register Modules in Plugins
1303
1304 When you register a plugin, its modules are automatically registered in the Medusa application. You don't have to register them manually in the `modules` configuration.
1305
1306 However, this isn't the case for module providers. If your plugin includes a module provider, you must register it in the `modules` configuration, referencing the module provider's path.
1307
1308 For example:
1309
1310 ```ts title="medusa-config.ts"
1311 module.exports = {
1312 plugins: [
1313 `medusa-my-plugin`,
1314 ],
1315 modules: [
1316 {
1317 resolve: "@medusajs/medusa/notification",
1318 options: {
1319 providers: [
1320 // ...
1321 {
1322 resolve: "medusa-my-plugin/providers/my-notification",
1323 id: "my-notification",
1324 options: {
1325 channels: ["email"],
1326 // provider options...
1327 },
1328 },
1329 ],
1330 },
1331 },
1332 ],
1333 // ...
1334 }
1335 ```
1336
1337 ---
1338
1339 ## Feature Flags (`featureFlags`)
1340
1341 The `featureFlags` configuration allows you to manage enabled beta features in the Medusa application.
1342
1343 Learn more in the [Feature Flags](../../debugging-and-testing/feature-flags/page.mdx) chapter.
1344
1345 ### Example
1346
1347 ```ts title="medusa-config.ts"
1348 module.exports = defineConfig({
1349 featureFlags: {
1350 index_engine: true,
1351 // ...
1352 },
1353 // ...
1354 })
1355 ```
1356
1357 ---
1358
1359 ## Custom Logger (`logger`)
1360
1361 The `logger` configuration allows you to override the default [Logger](../../debugging-and-testing/logging/page.mdx) used in the Medusa application with your custom implementation.
1362
1363 Learn more about creating a custom logger in the [Override Logger](../../debugging-and-testing/logging/custom-logger/page.mdx) chapter.
1364
1365 The `logger` configuration accepts an instance of a class that extends the `Logger` interface.
1366
1367 ### Example
1368
1369 ```ts title="medusa-config.ts"
1370 import { logger } from "./src/logger/my-logger"
1371
1372 module.exports = defineConfig({
1373 // ...
1374 logger,
1375 })
1376 ```