1
0

dev-config.ts 6.9 KB

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