dev-config.ts 5.8 KB

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