dev-config.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* tslint: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. examplePaymentHandler,
  12. LanguageCode,
  13. LogLevel,
  14. manualFulfillmentHandler,
  15. PaymentMethodEligibilityChecker,
  16. VendureConfig,
  17. } from '@vendure/core';
  18. import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
  19. import path from 'path';
  20. import { ConnectionOptions } from 'typeorm';
  21. const testPaymentChecker = new PaymentMethodEligibilityChecker({
  22. code: 'test-checker',
  23. description: [{ languageCode: LanguageCode.en, value: 'test checker' }],
  24. args: {},
  25. check: (ctx, order) => true,
  26. });
  27. /**
  28. * Config settings used during development
  29. */
  30. export const devConfig: VendureConfig = {
  31. apiOptions: {
  32. port: API_PORT,
  33. adminApiPath: ADMIN_API_PATH,
  34. adminApiPlayground: {
  35. settings: {
  36. 'request.credentials': 'include',
  37. } as any,
  38. },
  39. adminApiDebug: true,
  40. shopApiPath: SHOP_API_PATH,
  41. shopApiPlayground: {
  42. settings: {
  43. 'request.credentials': 'include',
  44. } as any,
  45. },
  46. shopApiDebug: true,
  47. },
  48. authOptions: {
  49. disableAuth: false,
  50. tokenMethod: 'cookie',
  51. sessionSecret: 'some-secret',
  52. requireVerification: true,
  53. customPermissions: [],
  54. },
  55. dbConnectionOptions: {
  56. synchronize: false,
  57. logging: false,
  58. migrations: [path.join(__dirname, 'migrations/*.ts')],
  59. ...getDbConfig(),
  60. },
  61. paymentOptions: {
  62. paymentMethodEligibilityCheckers: [testPaymentChecker],
  63. paymentMethodHandlers: [dummyPaymentHandler],
  64. },
  65. customFields: {
  66. /*Asset: [{ name: 'description', type: 'string' }],*/
  67. },
  68. logger: new DefaultLogger({ level: LogLevel.Info }),
  69. importExportOptions: {
  70. importAssetsDir: path.join(__dirname, 'import-assets'),
  71. },
  72. shippingOptions: {
  73. fulfillmentHandlers: [manualFulfillmentHandler],
  74. },
  75. plugins: [
  76. AssetServerPlugin.init({
  77. route: 'assets',
  78. assetUploadDir: path.join(__dirname, 'assets'),
  79. port: 5002,
  80. }),
  81. DefaultSearchPlugin,
  82. DefaultJobQueuePlugin,
  83. // ElasticsearchPlugin.init({
  84. // host: 'http://localhost',
  85. // port: 9200,
  86. // }),
  87. EmailPlugin.init({
  88. devMode: true,
  89. handlers: defaultEmailHandlers,
  90. templatePath: path.join(__dirname, '../email-plugin/templates'),
  91. outputPath: path.join(__dirname, 'test-emails'),
  92. mailboxPort: 5003,
  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. port: 5001,
  101. }),
  102. ],
  103. };
  104. function getDbConfig(): ConnectionOptions {
  105. const dbType = process.env.DB || 'mysql';
  106. switch (dbType) {
  107. case 'postgres':
  108. console.log('Using postgres connection');
  109. return {
  110. synchronize: true,
  111. type: 'postgres',
  112. host: '127.0.0.1',
  113. port: 5432,
  114. username: 'admin',
  115. password: 'secret',
  116. database: 'vendure-dev',
  117. };
  118. case 'sqlite':
  119. console.log('Using sqlite connection');
  120. return {
  121. synchronize: false,
  122. type: 'better-sqlite3',
  123. database: path.join(__dirname, 'vendure.sqlite'),
  124. };
  125. case 'sqljs':
  126. console.log('Using sql.js connection');
  127. return {
  128. type: 'sqljs',
  129. autoSave: true,
  130. database: new Uint8Array([]),
  131. location: path.join(__dirname, 'vendure.sqlite'),
  132. };
  133. case 'mysql':
  134. default:
  135. console.log('Using mysql connection');
  136. return {
  137. synchronize: true,
  138. type: 'mariadb',
  139. host: '127.0.0.1',
  140. port: 3306,
  141. username: 'root',
  142. password: '',
  143. database: 'vendure-dev',
  144. };
  145. }
  146. }