dev-config.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* tslint: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. Asset,
  7. DefaultJobQueuePlugin,
  8. DefaultLogger,
  9. defaultPromotionActions,
  10. DefaultSearchPlugin,
  11. dummyPaymentHandler,
  12. examplePaymentHandler,
  13. FulfillmentHandler,
  14. LanguageCode,
  15. LogLevel,
  16. manualFulfillmentHandler,
  17. PaymentMethodEligibilityChecker,
  18. PromotionItemAction,
  19. VendureConfig,
  20. } from '@vendure/core';
  21. import { ElasticsearchPlugin } from '@vendure/elasticsearch-plugin';
  22. import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
  23. import path from 'path';
  24. import { ConnectionOptions } from 'typeorm';
  25. const testPaymentChecker = new PaymentMethodEligibilityChecker({
  26. code: 'test-checker',
  27. description: [{ languageCode: LanguageCode.en, value: 'test checker' }],
  28. args: {},
  29. check: (ctx, order) => true,
  30. });
  31. const testPromoAction = new PromotionItemAction({
  32. code: 'discount-price-action',
  33. description: [{ languageCode: LanguageCode.en, value: 'Apply discount price' }],
  34. args: {},
  35. execute: (ctx, orderItem, orderLine) => {
  36. if ((orderLine.productVariant.customFields as any).discountPrice) {
  37. return -(
  38. orderLine.unitPriceWithTax - (orderLine.productVariant.customFields as any).discountPrice
  39. );
  40. }
  41. return 0;
  42. },
  43. });
  44. const myHandler = new FulfillmentHandler({
  45. code: 'test-handler',
  46. args: {},
  47. description: [{ languageCode: LanguageCode.en, value: 'test fulfillment handler' }],
  48. createFulfillment: ctx => {
  49. return {
  50. method: 'test-handler',
  51. trackingCode: '123123123123',
  52. customFields: {
  53. logoId: 1,
  54. },
  55. };
  56. },
  57. });
  58. /**
  59. * Config settings used during development
  60. */
  61. export const devConfig: VendureConfig = {
  62. apiOptions: {
  63. port: API_PORT,
  64. adminApiPath: ADMIN_API_PATH,
  65. adminApiPlayground: {
  66. settings: {
  67. 'request.credentials': 'include',
  68. } as any,
  69. },
  70. adminApiDebug: true,
  71. shopApiPath: SHOP_API_PATH,
  72. shopApiPlayground: {
  73. settings: {
  74. 'request.credentials': 'include',
  75. } as any,
  76. },
  77. shopApiDebug: true,
  78. },
  79. authOptions: {
  80. disableAuth: false,
  81. tokenMethod: 'cookie',
  82. requireVerification: true,
  83. customPermissions: [],
  84. },
  85. dbConnectionOptions: {
  86. synchronize: false,
  87. logging: false,
  88. migrations: [path.join(__dirname, 'migrations/*.ts')],
  89. ...getDbConfig(),
  90. },
  91. paymentOptions: {
  92. paymentMethodEligibilityCheckers: [testPaymentChecker],
  93. paymentMethodHandlers: [dummyPaymentHandler],
  94. },
  95. promotionOptions: {
  96. promotionActions: [...defaultPromotionActions, testPromoAction],
  97. },
  98. customFields: {
  99. /*Asset: [{ name: 'description', type: 'string' }],*/
  100. },
  101. logger: new DefaultLogger({ level: LogLevel.Info }),
  102. importExportOptions: {
  103. importAssetsDir: path.join(__dirname, 'import-assets'),
  104. },
  105. shippingOptions: {
  106. fulfillmentHandlers: [manualFulfillmentHandler, myHandler],
  107. },
  108. plugins: [
  109. AssetServerPlugin.init({
  110. route: 'assets',
  111. assetUploadDir: path.join(__dirname, 'assets'),
  112. }),
  113. DefaultSearchPlugin,
  114. DefaultJobQueuePlugin,
  115. // ElasticsearchPlugin.init({
  116. // host: 'http://localhost',
  117. // port: 9200,
  118. // }),
  119. EmailPlugin.init({
  120. devMode: true,
  121. route: 'mailbox',
  122. handlers: defaultEmailHandlers,
  123. templatePath: path.join(__dirname, '../email-plugin/templates'),
  124. outputPath: path.join(__dirname, 'test-emails'),
  125. globalTemplateVars: {
  126. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  127. passwordResetUrl: 'http://localhost:4201/reset-password',
  128. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  129. },
  130. }),
  131. AdminUiPlugin.init({
  132. route: 'admin',
  133. port: 5001,
  134. }),
  135. ],
  136. };
  137. function getDbConfig(): ConnectionOptions {
  138. const dbType = process.env.DB || 'mysql';
  139. switch (dbType) {
  140. case 'postgres':
  141. console.log('Using postgres connection');
  142. return {
  143. synchronize: true,
  144. type: 'postgres',
  145. host: '127.0.0.1',
  146. port: 5432,
  147. username: 'admin',
  148. password: 'secret',
  149. database: 'vendure-dev',
  150. };
  151. case 'sqlite':
  152. console.log('Using sqlite connection');
  153. return {
  154. synchronize: false,
  155. type: 'better-sqlite3',
  156. database: path.join(__dirname, 'vendure.sqlite'),
  157. };
  158. case 'sqljs':
  159. console.log('Using sql.js connection');
  160. return {
  161. type: 'sqljs',
  162. autoSave: true,
  163. database: new Uint8Array([]),
  164. location: path.join(__dirname, 'vendure.sqlite'),
  165. };
  166. case 'mysql':
  167. default:
  168. console.log('Using mysql connection');
  169. return {
  170. synchronize: true,
  171. type: 'mariadb',
  172. host: '127.0.0.1',
  173. port: 3306,
  174. username: 'root',
  175. password: '',
  176. database: 'vendure-dev',
  177. };
  178. }
  179. }