dev-config.ts 5.9 KB

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