dev-config.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. // Un-comment to compile a custom admin ui
  105. // app: compileUiExtensions({
  106. // outputPath: path.join(__dirname, './custom-admin-ui'),
  107. // extensions: [
  108. // {
  109. // id: 'ui-extensions-library',
  110. // extensionPath: path.join(__dirname, 'example-plugins/ui-extensions-library/ui'),
  111. // routes: [{ route: 'ui-library', filePath: 'routes.ts' }],
  112. // providers: ['providers.ts'],
  113. // },
  114. // {
  115. // globalStyles: path.join(
  116. // __dirname,
  117. // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  118. // ),
  119. // },
  120. // ],
  121. // devMode: true,
  122. // }),
  123. }),
  124. ],
  125. };
  126. function getDbConfig(): DataSourceOptions {
  127. const dbType = process.env.DB || 'mysql';
  128. switch (dbType) {
  129. case 'postgres':
  130. console.log('Using postgres connection');
  131. return {
  132. synchronize: true,
  133. type: 'postgres',
  134. host: process.env.DB_HOST || 'localhost',
  135. port: Number(process.env.DB_PORT) || 5432,
  136. username: process.env.DB_USERNAME || 'vendure',
  137. password: process.env.DB_PASSWORD || 'password',
  138. database: process.env.DB_NAME || 'vendure-dev',
  139. schema: process.env.DB_SCHEMA || 'public',
  140. };
  141. case 'sqlite':
  142. console.log('Using sqlite connection');
  143. return {
  144. synchronize: true,
  145. type: 'better-sqlite3',
  146. database: path.join(__dirname, 'vendure.sqlite'),
  147. };
  148. case 'sqljs':
  149. console.log('Using sql.js connection');
  150. return {
  151. type: 'sqljs',
  152. autoSave: true,
  153. database: new Uint8Array([]),
  154. location: path.join(__dirname, 'vendure.sqlite'),
  155. };
  156. case 'mysql':
  157. case 'mariadb':
  158. default:
  159. console.log('Using mysql connection');
  160. return {
  161. synchronize: true,
  162. type: 'mariadb',
  163. host: '127.0.0.1',
  164. port: 3306,
  165. username: 'vendure',
  166. password: 'password',
  167. database: 'vendure-dev',
  168. };
  169. }
  170. }