1
0

dev-config.ts 5.6 KB

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