dev-config.ts 6.1 KB

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