dev-config.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* eslint-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. LanguageCode,
  12. LogLevel,
  13. VendureConfig,
  14. } from '@vendure/core';
  15. import { ElasticsearchPlugin } from '@vendure/elasticsearch-plugin';
  16. import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
  17. import { BullMQJobQueuePlugin } from '@vendure/job-queue-plugin/package/bullmq';
  18. import 'dotenv/config';
  19. import { compileUiExtensions } from '@vendure/ui-devkit/compiler';
  20. import path from 'path';
  21. import { DataSourceOptions } from 'typeorm';
  22. import { MultivendorPlugin } from './example-plugins/multivendor-plugin/multivendor.plugin';
  23. /**
  24. * Config settings used during development
  25. */
  26. export const devConfig: VendureConfig = {
  27. apiOptions: {
  28. port: API_PORT,
  29. adminApiPath: ADMIN_API_PATH,
  30. adminApiPlayground: {
  31. settings: {
  32. 'request.credentials': 'include',
  33. },
  34. },
  35. adminApiDebug: true,
  36. shopApiPath: SHOP_API_PATH,
  37. shopApiPlayground: {
  38. settings: {
  39. 'request.credentials': 'include',
  40. },
  41. },
  42. shopApiDebug: true,
  43. },
  44. authOptions: {
  45. disableAuth: false,
  46. tokenMethod: ['bearer', 'cookie'] as const,
  47. requireVerification: true,
  48. customPermissions: [],
  49. cookieOptions: {
  50. secret: 'abc',
  51. },
  52. },
  53. dbConnectionOptions: {
  54. synchronize: false,
  55. logging: false,
  56. migrations: [path.join(__dirname, 'migrations/*.ts')],
  57. ...getDbConfig(),
  58. },
  59. paymentOptions: {
  60. paymentMethodHandlers: [dummyPaymentHandler],
  61. },
  62. customFields: {
  63. Product: [
  64. {
  65. name: 'secret',
  66. type: 'string',
  67. encryptionSecret: 'foo',
  68. },
  69. ],
  70. },
  71. logger: new DefaultLogger({ level: LogLevel.Verbose }),
  72. importExportOptions: {
  73. importAssetsDir: path.join(__dirname, 'import-assets'),
  74. },
  75. plugins: [
  76. // MultivendorPlugin.init({
  77. // platformFeePercent: 10,
  78. // platformFeeSKU: 'FEE',
  79. // }),
  80. AssetServerPlugin.init({
  81. route: 'assets',
  82. assetUploadDir: path.join(__dirname, 'assets'),
  83. }),
  84. DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
  85. BullMQJobQueuePlugin.init({}),
  86. // DefaultJobQueuePlugin.init({}),
  87. // JobQueueTestPlugin.init({ queueCount: 10 }),
  88. // ElasticsearchPlugin.init({
  89. // host: 'http://localhost',
  90. // port: 9200,
  91. // bufferUpdates: true,
  92. // }),
  93. EmailPlugin.init({
  94. devMode: true,
  95. route: 'mailbox',
  96. handlers: defaultEmailHandlers,
  97. templatePath: path.join(__dirname, '../email-plugin/templates'),
  98. outputPath: path.join(__dirname, 'test-emails'),
  99. globalTemplateVars: {
  100. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  101. passwordResetUrl: 'http://localhost:4201/reset-password',
  102. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  103. },
  104. }),
  105. AdminUiPlugin.init({
  106. route: 'admin',
  107. port: 5001,
  108. // Un-comment to compile a custom admin ui
  109. // app: compileUiExtensions({
  110. // outputPath: path.join(__dirname, './custom-admin-ui'),
  111. // extensions: [
  112. // {
  113. // id: 'ui-extensions-library',
  114. // extensionPath: path.join(__dirname, 'example-plugins/ui-extensions-library/ui'),
  115. // routes: [{ route: 'ui-library', filePath: 'routes.ts' }],
  116. // providers: ['providers.ts'],
  117. // },
  118. // {
  119. // globalStyles: path.join(
  120. // __dirname,
  121. // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  122. // ),
  123. // },
  124. // ],
  125. // devMode: true,
  126. // }),
  127. }),
  128. ],
  129. };
  130. function getDbConfig(): DataSourceOptions {
  131. const dbType = process.env.DB || 'mysql';
  132. switch (dbType) {
  133. case 'postgres':
  134. console.log('Using postgres connection');
  135. return {
  136. synchronize: false,
  137. type: 'postgres',
  138. host: process.env.DB_HOST || 'localhost',
  139. port: Number(process.env.DB_PORT) || 5432,
  140. username: process.env.DB_USERNAME || 'postgres',
  141. password: process.env.DB_PASSWORD || 'postgres',
  142. database: process.env.DB_NAME || 'vendure',
  143. schema: process.env.DB_SCHEMA || 'public',
  144. };
  145. case 'sqlite':
  146. console.log('Using sqlite connection');
  147. return {
  148. synchronize: false,
  149. type: 'better-sqlite3',
  150. database: path.join(__dirname, 'vendure.sqlite'),
  151. };
  152. case 'sqljs':
  153. console.log('Using sql.js connection');
  154. return {
  155. type: 'sqljs',
  156. autoSave: true,
  157. database: new Uint8Array([]),
  158. location: path.join(__dirname, 'vendure.sqlite'),
  159. };
  160. case 'mysql':
  161. default:
  162. console.log('Using mysql connection');
  163. return {
  164. synchronize: true,
  165. type: 'mariadb',
  166. host: '127.0.0.1',
  167. port: 3306,
  168. username: 'root',
  169. password: '',
  170. database: 'vendure-dev',
  171. };
  172. }
  173. }