dev-config.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* eslint-disable no-console */
  2. import { AdminUiPlugin } from '@vendure/admin-ui-plugin';
  3. import { AssetServerPlugin } from '@vendure/asset-server-plugin';
  4. import { ADMIN_API_PATH, API_PORT, SHOP_API_PATH } from '@vendure/common/lib/shared-constants';
  5. import {
  6. DefaultSearchPlugin,
  7. dummyPaymentHandler,
  8. LanguageCode,
  9. OtelLogger,
  10. VendureConfig,
  11. } from '@vendure/core';
  12. import { defaultEmailHandlers, EmailPlugin, FileBasedTemplateLoader } from '@vendure/email-plugin';
  13. import { BullMQJobQueuePlugin } from '@vendure/job-queue-plugin/package/bullmq';
  14. import 'dotenv/config';
  15. import path from 'path';
  16. import { DataSourceOptions } from 'typeorm';
  17. import { ReviewsPlugin } from './test-plugins/reviews/reviews-plugin';
  18. /**
  19. * Config settings used during development
  20. */
  21. export const devConfig: VendureConfig = {
  22. apiOptions: {
  23. port: API_PORT,
  24. adminApiPath: ADMIN_API_PATH,
  25. adminApiPlayground: {
  26. settings: {
  27. 'request.credentials': 'include',
  28. },
  29. },
  30. adminApiDebug: true,
  31. shopApiPath: SHOP_API_PATH,
  32. shopApiPlayground: {
  33. settings: {
  34. 'request.credentials': 'include',
  35. },
  36. },
  37. shopApiDebug: true,
  38. },
  39. authOptions: {
  40. disableAuth: false,
  41. tokenMethod: ['bearer', 'cookie'] as const,
  42. requireVerification: true,
  43. customPermissions: [],
  44. cookieOptions: {
  45. secret: 'abc',
  46. },
  47. },
  48. dbConnectionOptions: {
  49. synchronize: false,
  50. logging: false,
  51. migrations: [path.join(__dirname, 'migrations/*.ts')],
  52. ...getDbConfig(),
  53. },
  54. paymentOptions: {
  55. paymentMethodHandlers: [dummyPaymentHandler],
  56. },
  57. customFields: {
  58. Product: [
  59. {
  60. name: 'infoUrl',
  61. type: 'string',
  62. label: [{ languageCode: LanguageCode.en, value: 'Info URL' }],
  63. description: [{ languageCode: LanguageCode.en, value: 'Info URL' }],
  64. },
  65. {
  66. name: 'downloadable',
  67. type: 'boolean',
  68. label: [{ languageCode: LanguageCode.en, value: 'Downloadable' }],
  69. description: [{ languageCode: LanguageCode.en, value: 'Downloadable' }],
  70. },
  71. {
  72. name: 'shortName',
  73. type: 'localeString',
  74. label: [{ languageCode: LanguageCode.en, value: 'Short Name' }],
  75. description: [{ languageCode: LanguageCode.en, value: 'Short Name' }],
  76. },
  77. {
  78. name: 'lastUpdated',
  79. type: 'datetime',
  80. label: [{ languageCode: LanguageCode.en, value: 'Last Updated' }],
  81. description: [{ languageCode: LanguageCode.en, value: 'Last Updated' }],
  82. },
  83. ],
  84. },
  85. logger: new OtelLogger(),
  86. importExportOptions: {
  87. importAssetsDir: path.join(__dirname, 'import-assets'),
  88. },
  89. plugins: [
  90. // MultivendorPlugin.init({
  91. // platformFeePercent: 10,
  92. // platformFeeSKU: 'FEE',
  93. // }),
  94. ReviewsPlugin,
  95. AssetServerPlugin.init({
  96. route: 'assets',
  97. assetUploadDir: path.join(__dirname, 'assets'),
  98. }),
  99. DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
  100. // Enable if you need to debug the job queue
  101. BullMQJobQueuePlugin.init({}),
  102. //DefaultJobQueuePlugin.init({}),
  103. // JobQueueTestPlugin.init({ queueCount: 10 }),
  104. // ElasticsearchPlugin.init({
  105. // host: 'http://localhost',
  106. // port: 9200,
  107. // bufferUpdates: true,
  108. // }),
  109. EmailPlugin.init({
  110. devMode: true,
  111. route: 'mailbox',
  112. handlers: defaultEmailHandlers,
  113. templateLoader: new FileBasedTemplateLoader(path.join(__dirname, '../email-plugin/templates')),
  114. outputPath: path.join(__dirname, 'test-emails'),
  115. globalTemplateVars: {
  116. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  117. passwordResetUrl: 'http://localhost:4201/reset-password',
  118. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  119. },
  120. }),
  121. AdminUiPlugin.init({
  122. route: 'admin',
  123. port: 5001,
  124. adminUiConfig: {},
  125. // Un-comment to compile a custom admin ui
  126. // app: compileUiExtensions({
  127. // outputPath: path.join(__dirname, './custom-admin-ui'),
  128. // extensions: [
  129. // {
  130. // id: 'ui-extensions-library',
  131. // extensionPath: path.join(__dirname, 'example-plugins/ui-extensions-library/ui'),
  132. // routes: [{ route: 'ui-library', filePath: 'routes.ts' }],
  133. // providers: ['providers.ts'],
  134. // },
  135. // {
  136. // globalStyles: path.join(
  137. // __dirname,
  138. // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  139. // ),
  140. // },
  141. // ],
  142. // devMode: true,
  143. // }),
  144. }),
  145. ],
  146. };
  147. function getDbConfig(): DataSourceOptions {
  148. const dbType = process.env.DB || 'mysql';
  149. switch (dbType) {
  150. case 'postgres':
  151. console.log('Using postgres connection');
  152. return {
  153. synchronize: true,
  154. type: 'postgres',
  155. host: process.env.DB_HOST || 'localhost',
  156. port: Number(process.env.DB_PORT) || 5432,
  157. username: process.env.DB_USERNAME || 'vendure',
  158. password: process.env.DB_PASSWORD || 'password',
  159. database: process.env.DB_NAME || 'vendure-dev',
  160. schema: process.env.DB_SCHEMA || 'public',
  161. };
  162. case 'sqlite':
  163. console.log('Using sqlite connection');
  164. return {
  165. synchronize: true,
  166. type: 'better-sqlite3',
  167. database: path.join(__dirname, 'vendure.sqlite'),
  168. };
  169. case 'sqljs':
  170. console.log('Using sql.js connection');
  171. return {
  172. type: 'sqljs',
  173. autoSave: true,
  174. database: new Uint8Array([]),
  175. location: path.join(__dirname, 'vendure.sqlite'),
  176. };
  177. case 'mysql':
  178. case 'mariadb':
  179. default:
  180. console.log('Using mysql connection');
  181. return {
  182. synchronize: true,
  183. type: 'mariadb',
  184. host: '127.0.0.1',
  185. port: 3306,
  186. username: 'vendure',
  187. password: 'password',
  188. database: 'vendure-dev',
  189. };
  190. }
  191. }