dev-config.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. // passwordHashingStrategy: new PlaintextHashingStrategy(),
  48. },
  49. dbConnectionOptions: {
  50. synchronize: false,
  51. logging: false,
  52. migrations: [path.join(__dirname, 'migrations/*.ts')],
  53. ...getDbConfig(),
  54. },
  55. paymentOptions: {
  56. paymentMethodHandlers: [dummyPaymentHandler],
  57. },
  58. customFields: {},
  59. logger: new DefaultLogger({ level: LogLevel.Debug }),
  60. importExportOptions: {
  61. importAssetsDir: path.join(__dirname, 'import-assets'),
  62. },
  63. plugins: [
  64. AssetServerPlugin.init({
  65. route: 'assets',
  66. assetUploadDir: path.join(__dirname, 'assets'),
  67. }),
  68. DefaultSearchPlugin.init({ bufferUpdates: true, indexStockStatus: false }),
  69. BullMQJobQueuePlugin.init({}),
  70. // DefaultJobQueuePlugin.init(),
  71. // JobQueueTestPlugin.init({ queueCount: 10 }),
  72. // ElasticsearchPlugin.init({
  73. // host: 'http://localhost',
  74. // port: 9200,
  75. // bufferUpdates: true,
  76. // }),
  77. EmailPlugin.init({
  78. devMode: true,
  79. route: 'mailbox',
  80. handlers: defaultEmailHandlers,
  81. templatePath: path.join(__dirname, '../email-plugin/templates'),
  82. outputPath: path.join(__dirname, 'test-emails'),
  83. globalTemplateVars: {
  84. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  85. passwordResetUrl: 'http://localhost:4201/reset-password',
  86. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  87. },
  88. }),
  89. AdminUiPlugin.init({
  90. route: 'admin',
  91. port: 5001,
  92. }),
  93. ],
  94. };
  95. function getDbConfig(): ConnectionOptions {
  96. const dbType = process.env.DB || 'mysql';
  97. switch (dbType) {
  98. case 'postgres':
  99. console.log('Using postgres connection');
  100. return {
  101. synchronize: true,
  102. type: 'postgres',
  103. host: '127.0.0.1',
  104. port: 5432,
  105. username: 'admin',
  106. password: 'secret',
  107. database: 'vendure-dev',
  108. };
  109. case 'sqlite':
  110. console.log('Using sqlite connection');
  111. return {
  112. synchronize: false,
  113. type: 'better-sqlite3',
  114. database: path.join(__dirname, 'vendure.sqlite'),
  115. };
  116. case 'sqljs':
  117. console.log('Using sql.js connection');
  118. return {
  119. type: 'sqljs',
  120. autoSave: true,
  121. database: new Uint8Array([]),
  122. location: path.join(__dirname, 'vendure.sqlite'),
  123. };
  124. case 'mysql':
  125. default:
  126. console.log('Using mysql connection');
  127. return {
  128. synchronize: true,
  129. type: 'mariadb',
  130. host: '127.0.0.1',
  131. port: 3306,
  132. username: 'root',
  133. password: '',
  134. database: 'vendure-dev',
  135. };
  136. }
  137. }