dev-config.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. ProductVariant: [{ name: 'discountPrice', type: 'int' }],
  101. },
  102. logger: new DefaultLogger({ level: LogLevel.Info }),
  103. importExportOptions: {
  104. importAssetsDir: path.join(__dirname, 'import-assets'),
  105. },
  106. shippingOptions: {
  107. fulfillmentHandlers: [manualFulfillmentHandler, myHandler],
  108. },
  109. plugins: [
  110. AssetServerPlugin.init({
  111. route: 'assets',
  112. assetUploadDir: path.join(__dirname, 'assets'),
  113. }),
  114. DefaultSearchPlugin,
  115. DefaultJobQueuePlugin,
  116. // ElasticsearchPlugin.init({
  117. // host: 'http://localhost',
  118. // port: 9200,
  119. // }),
  120. EmailPlugin.init({
  121. devMode: true,
  122. route: 'mailbox',
  123. handlers: defaultEmailHandlers,
  124. templatePath: path.join(__dirname, '../email-plugin/templates'),
  125. outputPath: path.join(__dirname, 'test-emails'),
  126. globalTemplateVars: {
  127. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  128. passwordResetUrl: 'http://localhost:4201/reset-password',
  129. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  130. },
  131. }),
  132. AdminUiPlugin.init({
  133. route: 'admin',
  134. port: 5001,
  135. }),
  136. ],
  137. };
  138. function getDbConfig(): ConnectionOptions {
  139. const dbType = process.env.DB || 'mysql';
  140. switch (dbType) {
  141. case 'postgres':
  142. console.log('Using postgres connection');
  143. return {
  144. synchronize: true,
  145. type: 'postgres',
  146. host: '127.0.0.1',
  147. port: 5432,
  148. username: 'admin',
  149. password: 'secret',
  150. database: 'vendure-dev',
  151. };
  152. case 'sqlite':
  153. console.log('Using sqlite connection');
  154. return {
  155. synchronize: false,
  156. type: 'better-sqlite3',
  157. database: path.join(__dirname, 'vendure.sqlite'),
  158. };
  159. case 'sqljs':
  160. console.log('Using sql.js connection');
  161. return {
  162. type: 'sqljs',
  163. autoSave: true,
  164. database: new Uint8Array([]),
  165. location: path.join(__dirname, 'vendure.sqlite'),
  166. };
  167. case 'mysql':
  168. default:
  169. console.log('Using mysql connection');
  170. return {
  171. synchronize: true,
  172. type: 'mariadb',
  173. host: '127.0.0.1',
  174. port: 3306,
  175. username: 'root',
  176. password: '',
  177. database: 'vendure-dev',
  178. };
  179. }
  180. }