dev-config.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. DefaultSearchPlugin,
  9. dummyPaymentHandler,
  10. LanguageCode,
  11. LogLevel,
  12. DefaultSchedulerPlugin,
  13. VendureConfig,
  14. cleanSessionsTask,
  15. } from '@vendure/core';
  16. import { ScheduledTask } from '@vendure/core/dist/scheduler/scheduled-task';
  17. import { defaultEmailHandlers, EmailPlugin, FileBasedTemplateLoader } from '@vendure/email-plugin';
  18. import 'dotenv/config';
  19. import path from 'path';
  20. import { DataSourceOptions } from 'typeorm';
  21. import { MultivendorPlugin } from './example-plugins/multivendor-plugin/multivendor.plugin';
  22. import { ReviewsPlugin } from '@plugins/test-plugins/reviews/reviews-plugin';
  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. schedulerOptions: {
  95. tasks: [
  96. new ScheduledTask({
  97. id: 'test-job',
  98. description: 'A test job that doesn\'t do anything',
  99. schedule: '*/20 * * * * *',
  100. async execute(injector) {
  101. await new Promise(resolve => setTimeout(resolve, 10_000));
  102. return { success: true };
  103. },
  104. }),
  105. // cleanSessionsTask.configure({
  106. // schedule: cron => cron.every(1).minutes(),
  107. // params: {
  108. // batchSize: 10,
  109. // },
  110. // }),
  111. ],
  112. },
  113. plugins: [
  114. // MultivendorPlugin.init({
  115. // platformFeePercent: 10,
  116. // platformFeeSKU: 'FEE',
  117. // }),
  118. ReviewsPlugin,
  119. AssetServerPlugin.init({
  120. route: 'assets',
  121. assetUploadDir: path.join(__dirname, 'assets'),
  122. }),
  123. DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
  124. // Enable if you need to debug the job queue
  125. // BullMQJobQueuePlugin.init({}),
  126. DefaultJobQueuePlugin.init({}),
  127. // JobQueueTestPlugin.init({ queueCount: 10 }),
  128. // ElasticsearchPlugin.init({
  129. // host: 'http://localhost',
  130. // port: 9200,
  131. // bufferUpdates: true,
  132. // }),
  133. DefaultSchedulerPlugin.init({}),
  134. EmailPlugin.init({
  135. devMode: true,
  136. route: 'mailbox',
  137. handlers: defaultEmailHandlers,
  138. templateLoader: new FileBasedTemplateLoader(path.join(__dirname, '../email-plugin/templates')),
  139. outputPath: path.join(__dirname, 'test-emails'),
  140. globalTemplateVars: {
  141. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  142. passwordResetUrl: 'http://localhost:4201/reset-password',
  143. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  144. },
  145. }),
  146. AdminUiPlugin.init({
  147. route: 'admin',
  148. port: 5001,
  149. adminUiConfig: {},
  150. // Un-comment to compile a custom admin ui
  151. // app: compileUiExtensions({
  152. // outputPath: path.join(__dirname, './custom-admin-ui'),
  153. // extensions: [
  154. // {
  155. // id: 'ui-extensions-library',
  156. // extensionPath: path.join(__dirname, 'example-plugins/ui-extensions-library/ui'),
  157. // routes: [{ route: 'ui-library', filePath: 'routes.ts' }],
  158. // providers: ['providers.ts'],
  159. // },
  160. // {
  161. // globalStyles: path.join(
  162. // __dirname,
  163. // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  164. // ),
  165. // },
  166. // ],
  167. // devMode: true,
  168. // }),
  169. }),
  170. ],
  171. };
  172. function getDbConfig(): DataSourceOptions {
  173. const dbType = process.env.DB || 'mysql';
  174. switch (dbType) {
  175. case 'postgres':
  176. console.log('Using postgres connection');
  177. return {
  178. synchronize: true,
  179. type: 'postgres',
  180. host: process.env.DB_HOST || 'localhost',
  181. port: Number(process.env.DB_PORT) || 5432,
  182. username: process.env.DB_USERNAME || 'vendure',
  183. password: process.env.DB_PASSWORD || 'password',
  184. database: process.env.DB_NAME || 'vendure-dev',
  185. schema: process.env.DB_SCHEMA || 'public',
  186. };
  187. case 'sqlite':
  188. console.log('Using sqlite connection');
  189. return {
  190. synchronize: true,
  191. type: 'better-sqlite3',
  192. database: path.join(__dirname, 'vendure.sqlite'),
  193. };
  194. case 'sqljs':
  195. console.log('Using sql.js connection');
  196. return {
  197. type: 'sqljs',
  198. autoSave: true,
  199. database: new Uint8Array([]),
  200. location: path.join(__dirname, 'vendure.sqlite'),
  201. };
  202. case 'mysql':
  203. case 'mariadb':
  204. default:
  205. console.log('Using mysql connection');
  206. return {
  207. synchronize: true,
  208. type: 'mariadb',
  209. host: '127.0.0.1',
  210. port: 3306,
  211. username: 'vendure',
  212. password: 'password',
  213. database: 'vendure-dev',
  214. };
  215. }
  216. }