dev-config.ts 7.5 KB

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