|
@@ -29,6 +29,7 @@ import helmet from 'helmet'
|
|
import * as cors from 'cors'
|
|
import * as cors from 'cors'
|
|
import { text, json, Request, Response, NextFunction } from 'express'
|
|
import { text, json, Request, Response, NextFunction } from 'express'
|
|
import * as winston from 'winston'
|
|
import * as winston from 'winston'
|
|
|
|
+import * as AWSXRay from 'aws-xray-sdk'
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
const robots = require('express-robots-txt')
|
|
const robots = require('express-robots-txt')
|
|
|
|
|
|
@@ -36,15 +37,27 @@ import { InversifyExpressServer } from 'inversify-express-utils'
|
|
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
|
|
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
|
|
import { TYPES } from '../src/Bootstrap/Types'
|
|
import { TYPES } from '../src/Bootstrap/Types'
|
|
import { Env } from '../src/Bootstrap/Env'
|
|
import { Env } from '../src/Bootstrap/Env'
|
|
|
|
+import { ServiceIdentifier } from '@standardnotes/domain-core'
|
|
|
|
|
|
const container = new ContainerConfigLoader()
|
|
const container = new ContainerConfigLoader()
|
|
void container.load().then((container) => {
|
|
void container.load().then((container) => {
|
|
const env: Env = new Env()
|
|
const env: Env = new Env()
|
|
env.load()
|
|
env.load()
|
|
|
|
|
|
|
|
+ const isConfiguredForAWSProduction =
|
|
|
|
+ env.get('MODE', true) !== 'home-server' && env.get('MODE', true) !== 'self-hosted'
|
|
|
|
+
|
|
|
|
+ if (isConfiguredForAWSProduction) {
|
|
|
|
+ AWSXRay.config([AWSXRay.plugins.ECSPlugin])
|
|
|
|
+ }
|
|
|
|
+
|
|
const server = new InversifyExpressServer(container)
|
|
const server = new InversifyExpressServer(container)
|
|
|
|
|
|
server.setConfig((app) => {
|
|
server.setConfig((app) => {
|
|
|
|
+ if (isConfiguredForAWSProduction) {
|
|
|
|
+ app.use(AWSXRay.express.openSegment(ServiceIdentifier.NAMES.ApiGateway))
|
|
|
|
+ }
|
|
|
|
+
|
|
app.use((_request: Request, response: Response, next: NextFunction) => {
|
|
app.use((_request: Request, response: Response, next: NextFunction) => {
|
|
response.setHeader('X-API-Gateway-Version', container.get(TYPES.ApiGateway_VERSION))
|
|
response.setHeader('X-API-Gateway-Version', container.get(TYPES.ApiGateway_VERSION))
|
|
next()
|
|
next()
|
|
@@ -104,6 +117,10 @@ void container.load().then((container) => {
|
|
|
|
|
|
const serverInstance = server.build()
|
|
const serverInstance = server.build()
|
|
|
|
|
|
|
|
+ if (isConfiguredForAWSProduction) {
|
|
|
|
+ serverInstance.use(AWSXRay.express.closeSegment())
|
|
|
|
+ }
|
|
|
|
+
|
|
serverInstance.listen(env.get('PORT'))
|
|
serverInstance.listen(env.get('PORT'))
|
|
|
|
|
|
logger.info(`Server started on port ${process.env.PORT}`)
|
|
logger.info(`Server started on port ${process.env.PORT}`)
|