dev-config.ts 7.1 KB

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