dev-config.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 { GraphqlSubscriptionsPlugin } from './test-plugins/graphql-subscriptions/graphql-subscriptions-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: 'test',
  68. type: 'relation',
  69. entity: Asset,
  70. },
  71. ],
  72. FacetValue: [
  73. {
  74. name: 'childFacetValue',
  75. type: 'relation',
  76. entity: FacetValue,
  77. },
  78. ],
  79. },
  80. logger: new DefaultLogger({ level: LogLevel.Info }),
  81. importExportOptions: {
  82. importAssetsDir: path.join(__dirname, 'import-assets'),
  83. },
  84. plugins: [
  85. // MultivendorPlugin.init({
  86. // platformFeePercent: 10,
  87. // platformFeeSKU: 'FEE',
  88. // }),
  89. AssetServerPlugin.init({
  90. route: 'assets',
  91. assetUploadDir: path.join(__dirname, 'assets'),
  92. }),
  93. DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
  94. // Enable if you need to debug the job queue
  95. // BullMQJobQueuePlugin.init({}),
  96. DefaultJobQueuePlugin.init({}),
  97. // JobQueueTestPlugin.init({ queueCount: 10 }),
  98. // ElasticsearchPlugin.init({
  99. // host: 'http://localhost',
  100. // port: 9200,
  101. // bufferUpdates: true,
  102. // }),
  103. EmailPlugin.init({
  104. devMode: true,
  105. route: 'mailbox',
  106. handlers: defaultEmailHandlers,
  107. templateLoader: new FileBasedTemplateLoader(path.join(__dirname, '../email-plugin/templates')),
  108. outputPath: path.join(__dirname, 'test-emails'),
  109. globalTemplateVars: {
  110. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  111. passwordResetUrl: 'http://localhost:4201/reset-password',
  112. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  113. },
  114. }),
  115. AdminUiPlugin.init({
  116. route: 'admin',
  117. port: 5001,
  118. // Un-comment to compile a custom admin ui
  119. // app: compileUiExtensions({
  120. // outputPath: path.join(__dirname, './custom-admin-ui'),
  121. // extensions: [
  122. // {
  123. // id: 'ui-extensions-library',
  124. // extensionPath: path.join(__dirname, 'example-plugins/ui-extensions-library/ui'),
  125. // routes: [{ route: 'ui-library', filePath: 'routes.ts' }],
  126. // providers: ['providers.ts'],
  127. // },
  128. // {
  129. // globalStyles: path.join(
  130. // __dirname,
  131. // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  132. // ),
  133. // },
  134. // ],
  135. // devMode: true,
  136. // }),
  137. }),
  138. GraphqlSubscriptionsPlugin,
  139. ],
  140. };
  141. function getDbConfig(): DataSourceOptions {
  142. const dbType = process.env.DB || 'mysql';
  143. switch (dbType) {
  144. case 'postgres':
  145. console.log('Using postgres connection');
  146. return {
  147. synchronize: true,
  148. type: 'postgres',
  149. host: process.env.DB_HOST || 'localhost',
  150. port: Number(process.env.DB_PORT) || 5432,
  151. username: process.env.DB_USERNAME || 'vendure',
  152. password: process.env.DB_PASSWORD || 'password',
  153. database: process.env.DB_NAME || 'vendure-dev',
  154. schema: process.env.DB_SCHEMA || 'public',
  155. };
  156. case 'sqlite':
  157. console.log('Using sqlite connection');
  158. return {
  159. synchronize: true,
  160. type: 'better-sqlite3',
  161. database: path.join(__dirname, 'vendure.sqlite'),
  162. };
  163. case 'sqljs':
  164. console.log('Using sql.js connection');
  165. return {
  166. type: 'sqljs',
  167. autoSave: true,
  168. database: new Uint8Array([]),
  169. location: path.join(__dirname, 'vendure.sqlite'),
  170. };
  171. case 'mysql':
  172. case 'mariadb':
  173. default:
  174. console.log('Using mysql connection');
  175. return {
  176. synchronize: true,
  177. type: 'mariadb',
  178. host: '127.0.0.1',
  179. port: 3306,
  180. username: 'vendure',
  181. password: 'password',
  182. database: 'vendure-dev',
  183. };
  184. }
  185. }