1
0

dev-config.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. LogLevel,
  12. SettingsStoreScopes,
  13. VendureConfig,
  14. } from '@vendure/core';
  15. import { DashboardPlugin } from '@vendure/dashboard/plugin';
  16. import { defaultEmailHandlers, EmailPlugin, FileBasedTemplateLoader } from '@vendure/email-plugin';
  17. import { GraphiqlPlugin } from '@vendure/graphiql-plugin';
  18. import { SentryPlugin } from '@vendure/sentry-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. logger: new DefaultLogger({ level: LogLevel.Verbose }),
  77. importExportOptions: {
  78. importAssetsDir: path.join(__dirname, 'import-assets'),
  79. },
  80. plugins: [
  81. // MultivendorPlugin.init({
  82. // platformFeePercent: 10,
  83. // platformFeeSKU: 'FEE',
  84. // }),
  85. ReviewsPlugin,
  86. GraphiqlPlugin.init(),
  87. AssetServerPlugin.init({
  88. route: 'assets',
  89. assetUploadDir: path.join(__dirname, 'assets'),
  90. }),
  91. DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
  92. // Enable if you need to debug the job queue
  93. // BullMQJobQueuePlugin.init({}),
  94. DefaultJobQueuePlugin.init({}),
  95. // JobQueueTestPlugin.init({ queueCount: 10 }),
  96. // ElasticsearchPlugin.init({
  97. // host: 'http://localhost',
  98. // port: 9200,
  99. // bufferUpdates: true,
  100. // }),
  101. DefaultSchedulerPlugin.init({}),
  102. EmailPlugin.init({
  103. devMode: true,
  104. route: 'mailbox',
  105. handlers: defaultEmailHandlers,
  106. templateLoader: new FileBasedTemplateLoader(path.join(__dirname, '../email-plugin/templates')),
  107. outputPath: path.join(__dirname, 'test-emails'),
  108. globalTemplateVars: {
  109. verifyEmailAddressUrl: 'http://localhost:4201/verify',
  110. passwordResetUrl: 'http://localhost:4201/reset-password',
  111. changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
  112. },
  113. }),
  114. ...(IS_INSTRUMENTED ? [TelemetryPlugin.init({})] : []),
  115. ...(process.env.ENABLE_SENTRY === 'true' && process.env.SENTRY_DSN
  116. ? [
  117. SentryPlugin.init({
  118. includeErrorTestMutation: true,
  119. }),
  120. ]
  121. : []),
  122. // AdminUiPlugin.init({
  123. // route: 'admin',
  124. // port: 5001,
  125. // adminUiConfig: {},
  126. // // Un-comment to compile a custom admin ui
  127. // // app: compileUiExtensions({
  128. // // outputPath: path.join(__dirname, './custom-admin-ui'),
  129. // // extensions: [
  130. // // {
  131. // // id: 'ui-extensions-library',
  132. // // extensionPath: path.join(__dirname, 'example-plugins/ui-extensions-library/ui'),
  133. // // routes: [{ route: 'ui-library', filePath: 'routes.ts' }],
  134. // // providers: ['providers.ts'],
  135. // // },
  136. // // {
  137. // // globalStyles: path.join(
  138. // // __dirname,
  139. // // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  140. // // ),
  141. // // },
  142. // // ],
  143. // // devMode: true,
  144. // // }),
  145. // }),
  146. AdminUiPlugin.init({
  147. route: 'admin',
  148. port: 5001,
  149. adminUiConfig: {},
  150. // Un-comment to compile a custom admin ui
  151. // app: compileUiExtensions({
  152. // outputPath: path.join(__dirname, './custom-admin-ui'),
  153. // extensions: [
  154. // {
  155. // id: 'ui-extensions-library',
  156. // extensionPath: path.join(__dirname, 'example-plugins/ui-extensions-library/ui'),
  157. // routes: [{ route: 'ui-library', filePath: 'routes.ts' }],
  158. // providers: ['providers.ts'],
  159. // },
  160. // {
  161. // globalStyles: path.join(
  162. // __dirname,
  163. // 'test-plugins/with-ui-extension/ui/custom-theme.scss',
  164. // ),
  165. // },
  166. // ],
  167. // devMode: true,
  168. // }),
  169. }),
  170. DashboardPlugin.init({
  171. route: 'dashboard',
  172. appDir: path.join(__dirname, './dist'),
  173. }),
  174. ],
  175. };
  176. function getDbConfig(): DataSourceOptions {
  177. const dbType = process.env.DB || 'mysql';
  178. switch (dbType) {
  179. case 'postgres':
  180. console.log('Using postgres connection');
  181. return {
  182. synchronize: true,
  183. type: 'postgres',
  184. host: process.env.DB_HOST || 'localhost',
  185. port: Number(process.env.DB_PORT) || 5432,
  186. username: process.env.DB_USERNAME || 'vendure',
  187. password: process.env.DB_PASSWORD || 'password',
  188. database: process.env.DB_NAME || 'vendure-dev',
  189. schema: process.env.DB_SCHEMA || 'public',
  190. };
  191. case 'sqlite':
  192. console.log('Using sqlite connection');
  193. return {
  194. synchronize: true,
  195. type: 'better-sqlite3',
  196. database: path.join(__dirname, 'vendure.sqlite'),
  197. };
  198. case 'sqljs':
  199. console.log('Using sql.js connection');
  200. return {
  201. type: 'sqljs',
  202. autoSave: true,
  203. database: new Uint8Array([]),
  204. location: path.join(__dirname, 'vendure.sqlite'),
  205. };
  206. case 'mysql':
  207. case 'mariadb':
  208. default:
  209. console.log('Using mysql connection');
  210. return {
  211. synchronize: true,
  212. type: 'mariadb',
  213. host: '127.0.0.1',
  214. port: 3306,
  215. username: 'vendure',
  216. password: 'password',
  217. database: 'vendure-dev',
  218. };
  219. }
  220. }