dev-config.ts 4.2 KB

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