dev-config.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* eslint-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. LanguageCode,
  12. LogLevel,
  13. VendureConfig,
  14. } from '@vendure/core';
  15. import { ElasticsearchPlugin } from '@vendure/elasticsearch-plugin';
  16. import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
  17. import { BullMQJobQueuePlugin } from '@vendure/job-queue-plugin/package/bullmq';
  18. import 'dotenv/config';
  19. import { compileUiExtensions } from '@vendure/ui-devkit/compiler';
  20. import path from 'path';
  21. import { DataSourceOptions } from 'typeorm';
  22. import { MultivendorPlugin } from './example-plugins/multivendor-plugin/multivendor.plugin';
  23. /**
  24. * Config settings used during development
  25. */
  26. export const devConfig: VendureConfig = {
  27. apiOptions: {
  28. port: API_PORT,
  29. adminApiPath: ADMIN_API_PATH,
  30. adminApiPlayground: {
  31. settings: {
  32. 'request.credentials': 'include',
  33. },
  34. },
  35. adminApiDebug: true,
  36. shopApiPath: SHOP_API_PATH,
  37. shopApiPlayground: {
  38. settings: {
  39. 'request.credentials': 'include',
  40. },
  41. },
  42. shopApiDebug: true,
  43. },
  44. authOptions: {
  45. disableAuth: false,
  46. tokenMethod: ['bearer', 'cookie'] as const,
  47. requireVerification: true,
  48. customPermissions: [],
  49. cookieOptions: {
  50. secret: 'abc',
  51. },
  52. },
  53. dbConnectionOptions: {
  54. synchronize: false,
  55. logging: false,
  56. migrations: [path.join(__dirname, 'migrations/*.ts')],
  57. ...getDbConfig(),
  58. },
  59. paymentOptions: {
  60. paymentMethodHandlers: [dummyPaymentHandler],
  61. },
  62. customFields: {},
  63. logger: new DefaultLogger({ level: LogLevel.Verbose }),
  64. importExportOptions: {
  65. importAssetsDir: path.join(__dirname, 'import-assets'),
  66. },
  67. plugins: [
  68. // MultivendorPlugin.init({
  69. // platformFeePercent: 10,
  70. // platformFeeSKU: 'FEE',
  71. // }),
  72. AssetServerPlugin.init({
  73. route: 'assets',
  74. assetUploadDir: path.join(__dirname, 'assets'),
  75. }),
  76. DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
  77. BullMQJobQueuePlugin.init({}),
  78. // DefaultJobQueuePlugin.init({}),
  79. // JobQueueTestPlugin.init({ queueCount: 10 }),
  80. // ElasticsearchPlugin.init({
  81. // host: 'http://localhost',
  82. // port: 9200,
  83. // bufferUpdates: true,
  84. // }),
  85. EmailPlugin.init({
  86. devMode: true,
  87. route: 'mailbox',
  88. handlers: defaultEmailHandlers,
  89. templatePath: path.join(__dirname, '../email-plugin/templates'),
  90. outputPath: path.join(__dirname, 'test-emails'),
  91. globalTemplateVars: {
  92. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  93. passwordResetUrl: 'http://localhost:4201/reset-password',
  94. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  95. },
  96. }),
  97. AdminUiPlugin.init({
  98. route: 'admin',
  99. port: 5001,
  100. // Un-comment to compile a custom admin ui
  101. // app: compileUiExtensions({
  102. // outputPath: path.join(__dirname, './custom-admin-ui'),
  103. // extensions: [
  104. // {
  105. // id: 'test-ui-extension',
  106. // extensionPath: path.join(__dirname, 'test-plugins/with-ui-extension/ui'),
  107. // ngModules: [
  108. // {
  109. // type: 'lazy',
  110. // route: 'greetz',
  111. // ngModuleFileName: 'greeter.module.ts',
  112. // ngModuleName: 'GreeterModule',
  113. // },
  114. // {
  115. // type: 'shared',
  116. // ngModuleFileName: 'greeter-shared.module.ts',
  117. // ngModuleName: 'GreeterSharedModule',
  118. // },
  119. // ],
  120. // },
  121. // {
  122. // globalStyles: path.join(
  123. // __dirname,
  124. // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  125. // ),
  126. // },
  127. // {
  128. // id: 'external-ui-extension',
  129. // extensionPath: path.join(__dirname, 'test-plugins/with-external-ui-extension'),
  130. // ngModules: [
  131. // {
  132. // type: 'lazy',
  133. // route: 'greet',
  134. // ngModuleFileName: 'external-ui-extension.ts',
  135. // ngModuleName: 'ExternalUiExtensionModule',
  136. // },
  137. // ],
  138. // staticAssets: [
  139. // {
  140. // path: path.join(__dirname, 'test-plugins/with-external-ui-extension/app'),
  141. // rename: 'external-app',
  142. // },
  143. // ],
  144. // },
  145. // ],
  146. // devMode: true,
  147. // }),
  148. }),
  149. ],
  150. };
  151. function getDbConfig(): DataSourceOptions {
  152. const dbType = process.env.DB || 'mysql';
  153. switch (dbType) {
  154. case 'postgres':
  155. console.log('Using postgres connection');
  156. return {
  157. synchronize: false,
  158. type: 'postgres',
  159. host: process.env.DB_HOST || 'localhost',
  160. port: Number(process.env.DB_PORT) || 5432,
  161. username: process.env.DB_USERNAME || 'postgres',
  162. password: process.env.DB_PASSWORD || 'postgres',
  163. database: process.env.DB_NAME || 'vendure',
  164. schema: process.env.DB_SCHEMA || 'public',
  165. };
  166. case 'sqlite':
  167. console.log('Using sqlite connection');
  168. return {
  169. synchronize: false,
  170. type: 'better-sqlite3',
  171. database: path.join(__dirname, 'vendure.sqlite'),
  172. };
  173. case 'sqljs':
  174. console.log('Using sql.js connection');
  175. return {
  176. type: 'sqljs',
  177. autoSave: true,
  178. database: new Uint8Array([]),
  179. location: path.join(__dirname, 'vendure.sqlite'),
  180. };
  181. case 'mysql':
  182. default:
  183. console.log('Using mysql connection');
  184. return {
  185. synchronize: true,
  186. type: 'mariadb',
  187. host: '127.0.0.1',
  188. port: 3306,
  189. username: 'root',
  190. password: '',
  191. database: 'vendure2-dev',
  192. };
  193. }
  194. }