dev-config.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* eslint-disable no-console */
  2. import { AssetServerPlugin } from '@vendure/asset-server-plugin';
  3. import { ADMIN_API_PATH, API_PORT, SHOP_API_PATH } from '@vendure/common/lib/shared-constants';
  4. import {
  5. DefaultJobQueuePlugin,
  6. DefaultLogger,
  7. DefaultSchedulerPlugin,
  8. DefaultSearchPlugin,
  9. dummyPaymentHandler,
  10. LanguageCode,
  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. Product: [
  76. {
  77. name: 'infoUrl',
  78. type: 'string',
  79. label: [{ languageCode: LanguageCode.en, value: 'Info URL' }],
  80. description: [{ languageCode: LanguageCode.en, value: 'Info URL' }],
  81. },
  82. {
  83. name: 'downloadable',
  84. type: 'boolean',
  85. label: [{ languageCode: LanguageCode.en, value: 'Downloadable' }],
  86. description: [{ languageCode: LanguageCode.en, value: 'Downloadable' }],
  87. },
  88. {
  89. name: 'shortName',
  90. type: 'localeString',
  91. label: [{ languageCode: LanguageCode.en, value: 'Short Name' }],
  92. description: [{ languageCode: LanguageCode.en, value: 'Short Name' }],
  93. },
  94. {
  95. name: 'lastUpdated',
  96. type: 'datetime',
  97. label: [{ languageCode: LanguageCode.en, value: 'Last Updated' }],
  98. description: [{ languageCode: LanguageCode.en, value: 'Last Updated' }],
  99. },
  100. ],
  101. },
  102. logger: new DefaultLogger({ level: LogLevel.Verbose }),
  103. importExportOptions: {
  104. importAssetsDir: path.join(__dirname, 'import-assets'),
  105. },
  106. plugins: [
  107. // MultivendorPlugin.init({
  108. // platformFeePercent: 10,
  109. // platformFeeSKU: 'FEE',
  110. // }),
  111. ReviewsPlugin,
  112. GraphiqlPlugin.init(),
  113. AssetServerPlugin.init({
  114. route: 'assets',
  115. assetUploadDir: path.join(__dirname, 'assets'),
  116. }),
  117. DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
  118. // Enable if you need to debug the job queue
  119. // BullMQJobQueuePlugin.init({}),
  120. DefaultJobQueuePlugin.init({}),
  121. // JobQueueTestPlugin.init({ queueCount: 10 }),
  122. // ElasticsearchPlugin.init({
  123. // host: 'http://localhost',
  124. // port: 9200,
  125. // bufferUpdates: true,
  126. // }),
  127. DefaultSchedulerPlugin.init({}),
  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. ...(IS_INSTRUMENTED ? [TelemetryPlugin.init({})] : []),
  141. // AdminUiPlugin.init({
  142. // route: 'admin',
  143. // port: 5001,
  144. // adminUiConfig: {},
  145. // // Un-comment to compile a custom admin ui
  146. // // app: compileUiExtensions({
  147. // // outputPath: path.join(__dirname, './custom-admin-ui'),
  148. // // extensions: [
  149. // // {
  150. // // id: 'ui-extensions-library',
  151. // // extensionPath: path.join(__dirname, 'example-plugins/ui-extensions-library/ui'),
  152. // // routes: [{ route: 'ui-library', filePath: 'routes.ts' }],
  153. // // providers: ['providers.ts'],
  154. // // },
  155. // // {
  156. // // globalStyles: path.join(
  157. // // __dirname,
  158. // // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  159. // // ),
  160. // // },
  161. // // ],
  162. // // devMode: true,
  163. // // }),
  164. // }),
  165. DashboardPlugin.init({
  166. route: 'dashboard',
  167. appDir: path.join(__dirname, './dist'),
  168. }),
  169. ],
  170. };
  171. function getDbConfig(): DataSourceOptions {
  172. const dbType = process.env.DB || 'mysql';
  173. switch (dbType) {
  174. case 'postgres':
  175. console.log('Using postgres connection');
  176. return {
  177. synchronize: true,
  178. type: 'postgres',
  179. host: process.env.DB_HOST || 'localhost',
  180. port: Number(process.env.DB_PORT) || 5432,
  181. username: process.env.DB_USERNAME || 'vendure',
  182. password: process.env.DB_PASSWORD || 'password',
  183. database: process.env.DB_NAME || 'vendure-dev',
  184. schema: process.env.DB_SCHEMA || 'public',
  185. };
  186. case 'sqlite':
  187. console.log('Using sqlite connection');
  188. return {
  189. synchronize: true,
  190. type: 'better-sqlite3',
  191. database: path.join(__dirname, 'vendure.sqlite'),
  192. };
  193. case 'sqljs':
  194. console.log('Using sql.js connection');
  195. return {
  196. type: 'sqljs',
  197. autoSave: true,
  198. database: new Uint8Array([]),
  199. location: path.join(__dirname, 'vendure.sqlite'),
  200. };
  201. case 'mysql':
  202. case 'mariadb':
  203. default:
  204. console.log('Using mysql connection');
  205. return {
  206. synchronize: true,
  207. type: 'mariadb',
  208. host: '127.0.0.1',
  209. port: 3306,
  210. username: 'vendure',
  211. password: 'password',
  212. database: 'vendure-dev',
  213. };
  214. }
  215. }