dev-config.ts 4.6 KB

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