dev-config.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* tslint: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. DefaultJobQueuePlugin,
  7. DefaultLogger,
  8. DefaultSearchPlugin,
  9. dummyPaymentHandler,
  10. LogLevel,
  11. VendureConfig,
  12. } from '@vendure/core';
  13. import { ElasticsearchPlugin } from '@vendure/elasticsearch-plugin';
  14. import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
  15. import { BullMQJobQueuePlugin } from '@vendure/job-queue-plugin/package/bullmq';
  16. import path from 'path';
  17. import { ConnectionOptions } from 'typeorm';
  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. } as any,
  29. },
  30. adminApiDebug: true,
  31. shopApiPath: SHOP_API_PATH,
  32. shopApiPlayground: {
  33. settings: {
  34. 'request.credentials': 'include',
  35. } as any,
  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. Country: [{ name: 'foo', type: 'localeString' }],
  59. CustomerGroup: [{ name: 'foo', type: 'string' }],
  60. PaymentMethod: [{ name: 'foo', type: 'string' }],
  61. Promotion: [{ name: 'foo', type: 'string' }],
  62. TaxCategory: [{ name: 'foo', type: 'string' }],
  63. TaxRate: [{ name: 'foo', type: 'string' }],
  64. Zone: [{ name: 'foo', type: 'string' }],
  65. },
  66. logger: new DefaultLogger({ level: LogLevel.Debug }),
  67. importExportOptions: {
  68. importAssetsDir: path.join(__dirname, 'import-assets'),
  69. },
  70. plugins: [
  71. AssetServerPlugin.init({
  72. route: 'assets',
  73. assetUploadDir: path.join(__dirname, 'assets'),
  74. }),
  75. DefaultSearchPlugin.init({ bufferUpdates: true, indexStockStatus: false }),
  76. BullMQJobQueuePlugin.init({}),
  77. // DefaultJobQueuePlugin.init(),
  78. // JobQueueTestPlugin.init({ queueCount: 10 }),
  79. // ElasticsearchPlugin.init({
  80. // host: 'http://localhost',
  81. // port: 9200,
  82. // bufferUpdates: true,
  83. // }),
  84. EmailPlugin.init({
  85. devMode: true,
  86. route: 'mailbox',
  87. handlers: defaultEmailHandlers,
  88. templatePath: path.join(__dirname, '../email-plugin/templates'),
  89. outputPath: path.join(__dirname, 'test-emails'),
  90. globalTemplateVars: {
  91. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  92. passwordResetUrl: 'http://localhost:4201/reset-password',
  93. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  94. },
  95. }),
  96. AdminUiPlugin.init({
  97. route: 'admin',
  98. port: 5001,
  99. }),
  100. ],
  101. };
  102. function getDbConfig(): ConnectionOptions {
  103. const dbType = process.env.DB || 'mysql';
  104. switch (dbType) {
  105. case 'postgres':
  106. console.log('Using postgres connection');
  107. return {
  108. synchronize: true,
  109. type: 'postgres',
  110. host: '127.0.0.1',
  111. port: 5432,
  112. username: 'admin',
  113. password: 'secret',
  114. database: 'vendure-dev',
  115. };
  116. case 'sqlite':
  117. console.log('Using sqlite connection');
  118. return {
  119. synchronize: false,
  120. type: 'better-sqlite3',
  121. database: path.join(__dirname, 'vendure.sqlite'),
  122. };
  123. case 'sqljs':
  124. console.log('Using sql.js connection');
  125. return {
  126. type: 'sqljs',
  127. autoSave: true,
  128. database: new Uint8Array([]),
  129. location: path.join(__dirname, 'vendure.sqlite'),
  130. };
  131. case 'mysql':
  132. default:
  133. console.log('Using mysql connection');
  134. return {
  135. synchronize: true,
  136. type: 'mariadb',
  137. host: '127.0.0.1',
  138. port: 3306,
  139. username: 'root',
  140. password: '',
  141. database: 'vendure-dev',
  142. };
  143. }
  144. }