1
0

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