dev-config.ts 4.5 KB

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