1
0

dev-config.ts 7.6 KB

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