dev-config.ts 5.2 KB

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