dev-config.ts 6.5 KB

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