dev-config.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. LanguageCode,
  12. LogLevel,
  13. SettingsStoreScopes,
  14. VendureConfig,
  15. } from '@vendure/core';
  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. ],
  166. };
  167. function getDbConfig(): DataSourceOptions {
  168. const dbType = process.env.DB || 'mysql';
  169. switch (dbType) {
  170. case 'postgres':
  171. console.log('Using postgres connection');
  172. return {
  173. synchronize: true,
  174. type: 'postgres',
  175. host: process.env.DB_HOST || 'localhost',
  176. port: Number(process.env.DB_PORT) || 5432,
  177. username: process.env.DB_USERNAME || 'vendure',
  178. password: process.env.DB_PASSWORD || 'password',
  179. database: process.env.DB_NAME || 'vendure-dev',
  180. schema: process.env.DB_SCHEMA || 'public',
  181. };
  182. case 'sqlite':
  183. console.log('Using sqlite connection');
  184. return {
  185. synchronize: true,
  186. type: 'better-sqlite3',
  187. database: path.join(__dirname, 'vendure.sqlite'),
  188. };
  189. case 'sqljs':
  190. console.log('Using sql.js connection');
  191. return {
  192. type: 'sqljs',
  193. autoSave: true,
  194. database: new Uint8Array([]),
  195. location: path.join(__dirname, 'vendure.sqlite'),
  196. };
  197. case 'mysql':
  198. case 'mariadb':
  199. default:
  200. console.log('Using mysql connection');
  201. return {
  202. synchronize: true,
  203. type: 'mariadb',
  204. host: '127.0.0.1',
  205. port: 3306,
  206. username: 'vendure',
  207. password: 'password',
  208. database: 'vendure-dev',
  209. };
  210. }
  211. }