dev-config.ts 4.4 KB

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