dev-config.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 'dotenv/config';
  17. import path from 'path';
  18. import { ConnectionOptions } from 'typeorm';
  19. /**
  20. * Config settings used during development
  21. */
  22. export const devConfig: VendureConfig = {
  23. apiOptions: {
  24. port: API_PORT,
  25. adminApiPath: ADMIN_API_PATH,
  26. adminApiPlayground: {
  27. settings: {
  28. 'request.credentials': 'include',
  29. } as any,
  30. },
  31. adminApiDebug: true,
  32. shopApiPath: SHOP_API_PATH,
  33. shopApiPlayground: {
  34. settings: {
  35. 'request.credentials': 'include',
  36. } as any,
  37. },
  38. shopApiDebug: true,
  39. },
  40. authOptions: {
  41. disableAuth: false,
  42. tokenMethod: ['bearer', 'cookie'] as const,
  43. requireVerification: true,
  44. customPermissions: [],
  45. cookieOptions: {
  46. secret: 'abc',
  47. },
  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.Verbose }),
  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: process.env.DB_HOST || 'localhost',
  104. port: Number(process.env.DB_PORT) || 5432,
  105. username: process.env.DB_USERNAME || 'postgres',
  106. password: process.env.DB_PASSWORD || 'postgres',
  107. database: process.env.DB_NAME || 'vendure',
  108. schema: process.env.DB_SCHEMA || 'public',
  109. };
  110. case 'sqlite':
  111. console.log('Using sqlite connection');
  112. return {
  113. synchronize: false,
  114. type: 'better-sqlite3',
  115. database: path.join(__dirname, 'vendure.sqlite'),
  116. };
  117. case 'sqljs':
  118. console.log('Using sql.js connection');
  119. return {
  120. type: 'sqljs',
  121. autoSave: true,
  122. database: new Uint8Array([]),
  123. location: path.join(__dirname, 'vendure.sqlite'),
  124. };
  125. case 'mysql':
  126. default:
  127. console.log('Using mysql connection');
  128. return {
  129. synchronize: true,
  130. type: 'mariadb',
  131. host: '127.0.0.1',
  132. port: 3306,
  133. username: 'root',
  134. password: '',
  135. database: 'vendure-dev',
  136. };
  137. }
  138. }