dev-config.ts 5.1 KB

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