• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

decentraland / transactions-server / 8752792352

19 Apr 2024 11:25AM UTC coverage: 71.977% (-0.1%) from 72.115%
8752792352

push

github

web-flow
Merge pull request #117 from decentraland/fix/cors-split-missing

fix: add split to cors set up

64 of 87 branches covered (73.56%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

311 of 434 relevant lines covered (71.66%)

3.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/components.ts
1
import path from 'path'
×
2
import { createDotEnvConfigComponent } from '@well-known-components/env-config-provider'
×
3
import {
×
4
  createServerComponent,
5
  createStatusCheckComponent,
6
} from '@well-known-components/http-server'
7
import { createTracerComponent } from '@well-known-components/tracer-component'
×
8
import { createLogComponent } from '@well-known-components/logger'
×
9
import { createMetricsComponent } from '@well-known-components/metrics'
×
10
import { createSubgraphComponent } from '@well-known-components/thegraph-component'
×
11
import { createHttpTracerComponent } from '@well-known-components/http-tracer-component'
×
12
import {
×
13
  instrumentHttpServerWithRequestLogger,
14
  Verbosity,
15
} from '@well-known-components/http-requests-logger-component'
16
import { createPgComponent } from '@well-known-components/pg-component'
×
17
import { createContractsComponent } from './ports/contracts/component'
×
18
import { createFetchComponent } from './ports/fetcher'
×
19
import { createFeaturesComponent } from './ports/features'
×
20
import { createTransactionComponent } from './ports/transaction/component'
×
21
import { metricDeclarations } from './metrics'
×
22
import { AppComponents, GlobalContext } from './types'
23

24
export async function initComponents(): Promise<AppComponents> {
×
25
  // default config from process.env + .env file
26
  const config = await createDotEnvConfigComponent(
×
27
    { path: ['.env.defaults', '.env'] },
28
    process.env
29
  )
30

31
  const cors = {
×
32
    origin: (await config.requireString('CORS_ORIGIN'))
33
      .split(';')
NEW
34
      .map((origin) => new RegExp(origin)),
×
35
    method: await config.getString('CORS_METHOD'),
36
  }
37

38
  const tracer = createTracerComponent()
×
39

40
  const logs = await createLogComponent({ config, tracer })
×
41
  const server = await createServerComponent<GlobalContext>(
×
42
    { config, logs },
43
    { cors, compression: {} }
44
  )
45
  createHttpTracerComponent({ server, tracer })
×
46
  instrumentHttpServerWithRequestLogger(
×
47
    { server, logger: logs },
48
    { verbosity: Verbosity.INFO }
49
  )
50
  const statusChecks = await createStatusCheckComponent({ config, server })
×
51
  const fetcher = await createFetchComponent({ tracer })
×
52
  const features = await createFeaturesComponent(
×
53
    {
54
      config,
55
      logs,
56
      fetch: fetcher,
57
    },
58
    await config.requireString('TRANSACTIONS_SERVER_URL')
59
  )
60
  const metrics = await createMetricsComponent(metricDeclarations, {
×
61
    server,
62
    config,
63
  })
64

65
  let databaseUrl: string | undefined = await config.getString(
×
66
    'PG_COMPONENT_PSQL_CONNECTION_STRING'
67
  )
68

69
  if (!databaseUrl) {
×
70
    const dbUser = await config.requireString('PG_COMPONENT_PSQL_USER')
×
71
    const dbDatabaseName = await config.requireString(
×
72
      'PG_COMPONENT_PSQL_DATABASE'
73
    )
74
    const dbPort = await config.requireString('PG_COMPONENT_PSQL_PORT')
×
75
    const dbHost = await config.requireString('PG_COMPONENT_PSQL_HOST')
×
76
    const dbPassword = await config.requireString('PG_COMPONENT_PSQL_PASSWORD')
×
77
    databaseUrl = `postgres://${dbUser}:${dbPassword}@${dbHost}:${dbPort}/${dbDatabaseName}`
×
78
  }
79

80
  const pg = await createPgComponent(
×
81
    { logs, config, metrics },
82
    {
83
      migration: {
84
        databaseUrl,
85
        dir: path.resolve(__dirname, 'migrations'),
86
        migrationsTable: 'pgmigrations',
87
        ignorePattern: '.*\\.map',
88
        direction: 'up',
89
      },
90
    }
91
  )
92
  const collectionsSubgraph = await createSubgraphComponent(
×
93
    { config, logs, fetch: fetcher, metrics },
94
    await config.requireString('COLLECTIONS_SUBGRAPH_URL')
95
  )
96

97
  const contracts = createContractsComponent({
×
98
    config,
99
    fetcher,
100
    collectionsSubgraph,
101
  })
102

103
  const transaction = createTransactionComponent({
×
104
    config,
105
    features,
106
    fetcher,
107
    logs,
108
    pg,
109
    contracts,
110
    metrics,
111
  })
112
  const globalLogger = logs.getLogger('transactions-server')
×
113

114
  return {
×
115
    config,
116
    logs,
117
    globalLogger,
118
    fetcher,
119
    features,
120
    metrics,
121
    server,
122
    pg,
123
    transaction,
124
    contracts,
125
    collectionsSubgraph,
126
    statusChecks,
127
  }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc