dev-config.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. 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 'dotenv/config';
  17. import path from 'path';
  18. import { DataSourceOptions } from 'typeorm';
  19. import { MultivendorPlugin } from './test-plugins/multivendor-plugin/multivendor.plugin';
  20. /**
  21. * Config settings used during development
  22. */
  23. export const devConfig: VendureConfig = {
  24. apiOptions: {
  25. port: API_PORT,
  26. adminApiPath: ADMIN_API_PATH,
  27. adminApiPlayground: {
  28. settings: {
  29. 'request.credentials': 'include',
  30. } as any,
  31. },
  32. adminApiDebug: true,
  33. shopApiPath: SHOP_API_PATH,
  34. shopApiPlayground: {
  35. settings: {
  36. 'request.credentials': 'include',
  37. } as any,
  38. },
  39. shopApiDebug: true,
  40. },
  41. authOptions: {
  42. disableAuth: false,
  43. tokenMethod: ['bearer', 'cookie'] as const,
  44. requireVerification: true,
  45. customPermissions: [],
  46. cookieOptions: {
  47. secret: 'abc',
  48. },
  49. },
  50. dbConnectionOptions: {
  51. synchronize: false,
  52. logging: false,
  53. migrations: [path.join(__dirname, 'migrations/*.ts')],
  54. ...getDbConfig(),
  55. },
  56. paymentOptions: {
  57. paymentMethodHandlers: [dummyPaymentHandler],
  58. },
  59. customFields: {},
  60. logger: new DefaultLogger({ level: LogLevel.Verbose }),
  61. importExportOptions: {
  62. importAssetsDir: path.join(__dirname, 'import-assets'),
  63. },
  64. plugins: [
  65. // MultivendorPlugin,
  66. AssetServerPlugin.init({
  67. route: 'assets',
  68. assetUploadDir: path.join(__dirname, 'assets'),
  69. }),
  70. DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
  71. BullMQJobQueuePlugin.init({}),
  72. // DefaultJobQueuePlugin.init({}),
  73. // JobQueueTestPlugin.init({ queueCount: 10 }),
  74. // ElasticsearchPlugin.init({
  75. // host: 'http://localhost',
  76. // port: 9200,
  77. // bufferUpdates: true,
  78. // }),
  79. EmailPlugin.init({
  80. devMode: true,
  81. route: 'mailbox',
  82. handlers: defaultEmailHandlers,
  83. templatePath: path.join(__dirname, '../email-plugin/templates'),
  84. outputPath: path.join(__dirname, 'test-emails'),
  85. globalTemplateVars: {
  86. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  87. passwordResetUrl: 'http://localhost:4201/reset-password',
  88. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  89. },
  90. }),
  91. AdminUiPlugin.init({
  92. route: 'admin',
  93. port: 5001,
  94. }),
  95. ],
  96. };
  97. function getDbConfig(): DataSourceOptions {
  98. const dbType = process.env.DB || 'mysql';
  99. switch (dbType) {
  100. case 'postgres':
  101. console.log('Using postgres connection');
  102. return {
  103. synchronize: true,
  104. type: 'postgres',
  105. host: process.env.DB_HOST || 'localhost',
  106. port: Number(process.env.DB_PORT) || 5432,
  107. username: process.env.DB_USERNAME || 'postgres',
  108. password: process.env.DB_PASSWORD || 'postgres',
  109. database: process.env.DB_NAME || 'vendure',
  110. schema: process.env.DB_SCHEMA || 'public',
  111. };
  112. case 'sqlite':
  113. console.log('Using sqlite connection');
  114. return {
  115. synchronize: false,
  116. type: 'better-sqlite3',
  117. database: path.join(__dirname, 'vendure.sqlite'),
  118. };
  119. case 'sqljs':
  120. console.log('Using sql.js connection');
  121. return {
  122. type: 'sqljs',
  123. autoSave: true,
  124. database: new Uint8Array([]),
  125. location: path.join(__dirname, 'vendure.sqlite'),
  126. };
  127. case 'mysql':
  128. default:
  129. console.log('Using mysql connection');
  130. return {
  131. synchronize: true,
  132. type: 'mariadb',
  133. host: '127.0.0.1',
  134. port: 3306,
  135. username: 'root',
  136. password: '',
  137. database: 'vendure-dev',
  138. };
  139. }
  140. }