dev-config.ts 6.1 KB

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