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. 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. ui: {
  34. component: 'select-form-input',
  35. options: [{ value: 'first_class' }, { value: 'priority' }, { value: 'standard' }],
  36. },
  37. },
  38. },
  39. createFulfillment: async (ctx, orders, orderItems, args) => {
  40. return {
  41. method: `Ship-o-matic ${args.preferredService}`,
  42. trackingCode: 'SHIP-' + Math.random().toString(36).substr(3),
  43. };
  44. },
  45. onFulfillmentTransition: async (fromState, toState, { fulfillment }) => {
  46. Logger.info(`Transitioned Fulfillment ${fulfillment.trackingCode} to state ${toState}`);
  47. },
  48. });
  49. const pickupFulfillmentHandler = new FulfillmentHandler({
  50. code: 'customer-collect',
  51. description: [
  52. {
  53. languageCode: LanguageCode.en,
  54. value: 'Customer collect fulfillment',
  55. },
  56. ],
  57. args: {},
  58. createFulfillment: async (ctx, orders, orderItems, args) => {
  59. return {
  60. method: `Customer collect`,
  61. };
  62. },
  63. });
  64. /**
  65. * Config settings used during development
  66. */
  67. export const devConfig: VendureConfig = {
  68. apiOptions: {
  69. port: API_PORT,
  70. adminApiPath: ADMIN_API_PATH,
  71. adminApiPlayground: {
  72. settings: {
  73. 'request.credentials': 'include',
  74. } as any,
  75. },
  76. adminApiDebug: true,
  77. shopApiPath: SHOP_API_PATH,
  78. shopApiPlayground: {
  79. settings: {
  80. 'request.credentials': 'include',
  81. } as any,
  82. },
  83. shopApiDebug: true,
  84. },
  85. authOptions: {
  86. disableAuth: false,
  87. tokenMethod: 'cookie',
  88. sessionSecret: 'some-secret',
  89. requireVerification: true,
  90. customPermissions: [],
  91. },
  92. dbConnectionOptions: {
  93. synchronize: false,
  94. logging: false,
  95. migrations: [path.join(__dirname, 'migrations/*.ts')],
  96. ...getDbConfig(),
  97. },
  98. paymentOptions: {
  99. paymentMethodHandlers: [examplePaymentHandler],
  100. },
  101. customFields: {},
  102. logger: new DefaultLogger({ level: LogLevel.Info }),
  103. importExportOptions: {
  104. importAssetsDir: path.join(__dirname, 'import-assets'),
  105. },
  106. shippingOptions: {
  107. fulfillmentHandlers: [manualFulfillmentHandler, customFulfillmentHandler, pickupFulfillmentHandler],
  108. },
  109. plugins: [
  110. AssetServerPlugin.init({
  111. route: 'assets',
  112. assetUploadDir: path.join(__dirname, 'assets'),
  113. port: 5002,
  114. }),
  115. DefaultSearchPlugin,
  116. DefaultJobQueuePlugin,
  117. // ElasticsearchPlugin.init({
  118. // host: 'http://localhost',
  119. // port: 9200,
  120. // }),
  121. EmailPlugin.init({
  122. devMode: true,
  123. handlers: defaultEmailHandlers,
  124. templatePath: path.join(__dirname, '../email-plugin/templates'),
  125. outputPath: path.join(__dirname, 'test-emails'),
  126. mailboxPort: 5003,
  127. globalTemplateVars: {
  128. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  129. passwordResetUrl: 'http://localhost:4201/reset-password',
  130. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  131. },
  132. }),
  133. AdminUiPlugin.init({
  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. }