dev-config.ts 4.5 KB

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