dev-config.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. /*Administrator: [
  67. { name: 'profileLink', type: 'string' },
  68. { name: 'avatar', type: 'relation', entity: Asset },
  69. ],
  70. Channel: [{ name: 'description', type: 'string' }],*/
  71. },
  72. logger: new DefaultLogger({ level: LogLevel.Info }),
  73. importExportOptions: {
  74. importAssetsDir: path.join(__dirname, 'import-assets'),
  75. },
  76. shippingOptions: {
  77. fulfillmentHandlers: [manualFulfillmentHandler],
  78. },
  79. plugins: [
  80. AssetServerPlugin.init({
  81. route: 'assets',
  82. assetUploadDir: path.join(__dirname, 'assets'),
  83. port: 5002,
  84. }),
  85. DefaultSearchPlugin,
  86. DefaultJobQueuePlugin,
  87. // ElasticsearchPlugin.init({
  88. // host: 'http://localhost',
  89. // port: 9200,
  90. // }),
  91. EmailPlugin.init({
  92. devMode: true,
  93. handlers: defaultEmailHandlers,
  94. templatePath: path.join(__dirname, '../email-plugin/templates'),
  95. outputPath: path.join(__dirname, 'test-emails'),
  96. mailboxPort: 5003,
  97. globalTemplateVars: {
  98. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  99. passwordResetUrl: 'http://localhost:4201/reset-password',
  100. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  101. },
  102. }),
  103. AdminUiPlugin.init({
  104. port: 5001,
  105. }),
  106. ],
  107. };
  108. function getDbConfig(): ConnectionOptions {
  109. const dbType = process.env.DB || 'mysql';
  110. switch (dbType) {
  111. case 'postgres':
  112. console.log('Using postgres connection');
  113. return {
  114. synchronize: true,
  115. type: 'postgres',
  116. host: '127.0.0.1',
  117. port: 5432,
  118. username: 'admin',
  119. password: 'secret',
  120. database: 'vendure-dev',
  121. };
  122. case 'sqlite':
  123. console.log('Using sqlite connection');
  124. return {
  125. synchronize: false,
  126. type: 'better-sqlite3',
  127. database: path.join(__dirname, 'vendure.sqlite'),
  128. };
  129. case 'sqljs':
  130. console.log('Using sql.js connection');
  131. return {
  132. type: 'sqljs',
  133. autoSave: true,
  134. database: new Uint8Array([]),
  135. location: path.join(__dirname, 'vendure.sqlite'),
  136. };
  137. case 'mysql':
  138. default:
  139. console.log('Using mysql connection');
  140. return {
  141. synchronize: true,
  142. type: 'mariadb',
  143. host: '127.0.0.1',
  144. port: 3306,
  145. username: 'root',
  146. password: '',
  147. database: 'vendure-dev',
  148. };
  149. }
  150. }