dev-config.ts 7.1 KB

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