dev-config.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 { ScheduledTask } from '@vendure/core/dist/scheduler/scheduled-task';
  16. import { DashboardPlugin, DbIndexingStrategy, DbSearchStrategy } from '@vendure/dashboard-plugin';
  17. import { defaultEmailHandlers, EmailPlugin, FileBasedTemplateLoader } from '@vendure/email-plugin';
  18. import { GraphiqlPlugin } from '@vendure/graphiql-plugin';
  19. import 'dotenv/config';
  20. import path from 'path';
  21. import { DataSourceOptions } from 'typeorm';
  22. /**
  23. * Config settings used during development
  24. */
  25. export const devConfig: VendureConfig = {
  26. apiOptions: {
  27. port: API_PORT,
  28. adminApiPath: ADMIN_API_PATH,
  29. adminApiPlayground: {
  30. settings: {
  31. 'request.credentials': 'include',
  32. },
  33. },
  34. adminApiDebug: true,
  35. shopApiPath: SHOP_API_PATH,
  36. shopApiPlayground: {
  37. settings: {
  38. 'request.credentials': 'include',
  39. },
  40. },
  41. shopApiDebug: true,
  42. },
  43. authOptions: {
  44. disableAuth: false,
  45. tokenMethod: ['bearer', 'cookie'] as const,
  46. requireVerification: true,
  47. customPermissions: [],
  48. cookieOptions: {
  49. secret: 'abc',
  50. },
  51. },
  52. dbConnectionOptions: {
  53. synchronize: false,
  54. logging: false,
  55. migrations: [path.join(__dirname, 'migrations/*.ts')],
  56. ...getDbConfig(),
  57. },
  58. paymentOptions: {
  59. paymentMethodHandlers: [dummyPaymentHandler],
  60. },
  61. customFields: {
  62. Product: [
  63. {
  64. name: 'infoUrl',
  65. type: 'string',
  66. label: [{ languageCode: LanguageCode.en, value: 'Info URL' }],
  67. description: [{ languageCode: LanguageCode.en, value: 'Info URL' }],
  68. },
  69. {
  70. name: 'downloadable',
  71. type: 'boolean',
  72. label: [{ languageCode: LanguageCode.en, value: 'Downloadable' }],
  73. description: [{ languageCode: LanguageCode.en, value: 'Downloadable' }],
  74. },
  75. {
  76. name: 'shortName',
  77. type: 'localeString',
  78. label: [{ languageCode: LanguageCode.en, value: 'Short Name' }],
  79. description: [{ languageCode: LanguageCode.en, value: 'Short Name' }],
  80. },
  81. {
  82. name: 'lastUpdated',
  83. type: 'datetime',
  84. label: [{ languageCode: LanguageCode.en, value: 'Last Updated' }],
  85. description: [{ languageCode: LanguageCode.en, value: 'Last Updated' }],
  86. },
  87. ],
  88. },
  89. logger: new DefaultLogger({ level: LogLevel.Verbose }),
  90. importExportOptions: {
  91. importAssetsDir: path.join(__dirname, 'import-assets'),
  92. },
  93. schedulerOptions: {
  94. tasks: [
  95. new ScheduledTask({
  96. id: 'test-job',
  97. description: "A test job that doesn't do anything",
  98. schedule: '*/20 * * * * *',
  99. async execute(injector) {
  100. await new Promise(resolve => setTimeout(resolve, 10_000));
  101. return { success: true };
  102. },
  103. }),
  104. // cleanSessionsTask.configure({
  105. // schedule: cron => cron.every(1).minutes(),
  106. // params: {
  107. // batchSize: 10,
  108. // },
  109. // }),
  110. ],
  111. },
  112. plugins: [
  113. // MultivendorPlugin.init({
  114. // platformFeePercent: 10,
  115. // platformFeeSKU: 'FEE',
  116. // }),
  117. GraphiqlPlugin.init(),
  118. AssetServerPlugin.init({
  119. route: 'assets',
  120. assetUploadDir: path.join(__dirname, 'assets'),
  121. }),
  122. DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
  123. // Enable if you need to debug the job queue
  124. // BullMQJobQueuePlugin.init({}),
  125. DefaultJobQueuePlugin.init({}),
  126. // JobQueueTestPlugin.init({ queueCount: 10 }),
  127. // ElasticsearchPlugin.init({
  128. // host: 'http://localhost',
  129. // port: 9200,
  130. // bufferUpdates: true,
  131. // }),
  132. DefaultSchedulerPlugin.init({}),
  133. EmailPlugin.init({
  134. devMode: true,
  135. route: 'mailbox',
  136. handlers: defaultEmailHandlers,
  137. templateLoader: new FileBasedTemplateLoader(path.join(__dirname, '../email-plugin/templates')),
  138. outputPath: path.join(__dirname, 'test-emails'),
  139. globalTemplateVars: {
  140. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  141. passwordResetUrl: 'http://localhost:4201/reset-password',
  142. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  143. },
  144. }),
  145. AdminUiPlugin.init({
  146. route: 'admin',
  147. port: 5001,
  148. adminUiConfig: {},
  149. // Un-comment to compile a custom admin ui
  150. // app: compileUiExtensions({
  151. // outputPath: path.join(__dirname, './custom-admin-ui'),
  152. // extensions: [
  153. // {
  154. // id: 'ui-extensions-library',
  155. // extensionPath: path.join(__dirname, 'example-plugins/ui-extensions-library/ui'),
  156. // routes: [{ route: 'ui-library', filePath: 'routes.ts' }],
  157. // providers: ['providers.ts'],
  158. // },
  159. // {
  160. // globalStyles: path.join(
  161. // __dirname,
  162. // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  163. // ),
  164. // },
  165. // ],
  166. // devMode: true,
  167. // }),
  168. }),
  169. DashboardPlugin.init({
  170. searchStrategy: new DbSearchStrategy(),
  171. indexingStrategy: new DbIndexingStrategy(),
  172. }),
  173. ],
  174. };
  175. function getDbConfig(): DataSourceOptions {
  176. const dbType = process.env.DB || 'mysql';
  177. switch (dbType) {
  178. case 'postgres':
  179. console.log('Using postgres connection');
  180. return {
  181. synchronize: true,
  182. type: 'postgres',
  183. host: process.env.DB_HOST || 'localhost',
  184. port: Number(process.env.DB_PORT) || 5432,
  185. username: process.env.DB_USERNAME || 'vendure',
  186. password: process.env.DB_PASSWORD || 'password',
  187. database: process.env.DB_NAME || 'vendure-dev',
  188. schema: process.env.DB_SCHEMA || 'public',
  189. };
  190. case 'sqlite':
  191. console.log('Using sqlite connection');
  192. return {
  193. synchronize: true,
  194. type: 'better-sqlite3',
  195. database: path.join(__dirname, 'vendure.sqlite'),
  196. };
  197. case 'sqljs':
  198. console.log('Using sql.js connection');
  199. return {
  200. type: 'sqljs',
  201. autoSave: true,
  202. database: new Uint8Array([]),
  203. location: path.join(__dirname, 'vendure.sqlite'),
  204. };
  205. case 'mysql':
  206. case 'mariadb':
  207. default:
  208. console.log('Using mysql connection');
  209. return {
  210. synchronize: true,
  211. type: 'mariadb',
  212. host: '127.0.0.1',
  213. port: 3306,
  214. username: 'vendure',
  215. password: 'password',
  216. database: 'vendure-dev',
  217. };
  218. }
  219. }