1
0

dev-config.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. // Enable if you need to debug the job queue
  78. // BullMQJobQueuePlugin.init({}),
  79. DefaultJobQueuePlugin.init({}),
  80. // JobQueueTestPlugin.init({ queueCount: 10 }),
  81. // ElasticsearchPlugin.init({
  82. // host: 'http://localhost',
  83. // port: 9200,
  84. // bufferUpdates: true,
  85. // }),
  86. EmailPlugin.init({
  87. devMode: true,
  88. route: 'mailbox',
  89. handlers: defaultEmailHandlers,
  90. templatePath: path.join(__dirname, '../email-plugin/templates'),
  91. outputPath: path.join(__dirname, 'test-emails'),
  92. globalTemplateVars: {
  93. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  94. passwordResetUrl: 'http://localhost:4201/reset-password',
  95. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  96. },
  97. }),
  98. AdminUiPlugin.init({
  99. route: 'admin',
  100. port: 5001,
  101. // Un-comment to compile a custom admin ui
  102. // app: compileUiExtensions({
  103. // outputPath: path.join(__dirname, './custom-admin-ui'),
  104. // extensions: [
  105. // {
  106. // id: 'ui-extensions-library',
  107. // extensionPath: path.join(__dirname, 'example-plugins/ui-extensions-library/ui'),
  108. // routes: [{ route: 'ui-library', filePath: 'routes.ts' }],
  109. // providers: ['providers.ts'],
  110. // },
  111. // {
  112. // globalStyles: path.join(
  113. // __dirname,
  114. // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  115. // ),
  116. // },
  117. // ],
  118. // devMode: true,
  119. // }),
  120. }),
  121. ],
  122. };
  123. function getDbConfig(): DataSourceOptions {
  124. const dbType = process.env.DB || 'mysql';
  125. switch (dbType) {
  126. case 'postgres':
  127. console.log('Using postgres connection');
  128. return {
  129. synchronize: false,
  130. type: 'postgres',
  131. host: process.env.DB_HOST || 'localhost',
  132. port: Number(process.env.DB_PORT) || 5432,
  133. username: process.env.DB_USERNAME || 'postgres',
  134. password: process.env.DB_PASSWORD || 'postgres',
  135. database: process.env.DB_NAME || 'vendure',
  136. schema: process.env.DB_SCHEMA || 'public',
  137. };
  138. case 'sqlite':
  139. console.log('Using sqlite connection');
  140. return {
  141. synchronize: false,
  142. type: 'better-sqlite3',
  143. database: path.join(__dirname, 'vendure.sqlite'),
  144. };
  145. case 'sqljs':
  146. console.log('Using sql.js connection');
  147. return {
  148. type: 'sqljs',
  149. autoSave: true,
  150. database: new Uint8Array([]),
  151. location: path.join(__dirname, 'vendure.sqlite'),
  152. };
  153. case 'mysql':
  154. default:
  155. console.log('Using mysql connection');
  156. return {
  157. synchronize: true,
  158. type: 'mariadb',
  159. host: '127.0.0.1',
  160. port: 3306,
  161. username: 'root',
  162. password: '',
  163. database: 'vendure-dev',
  164. };
  165. }
  166. }