dev-config.ts 3.9 KB

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