dev-config.ts 4.3 KB

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