dev-config.ts 6.3 KB

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