Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
feat: improved status; added ESI_ENDPOINT to env
Browse files Browse the repository at this point in the history
  • Loading branch information
mentos1386 committed Jul 15, 2018
1 parent 855543b commit 49eaebe
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 14 deletions.
29 changes: 21 additions & 8 deletions docker-compose.yml
Expand Up @@ -5,8 +5,21 @@ services:
postgres:
image: postgres:latest

redis:
image: redis:latest
esi-nginx:
image: nginx:alpine
volumes:
- ./infra/esi-cache/nginx-esi.conf:/etc/nginx/nginx.conf:ro

esi-varnish:
image: million12/varnish
environment:
- VCL_CONFIG=/varnish-esi.vcl
volumes:
- ./infra/esi-cache/varnish-esi.vcl:/varnish-esi.vcl:ro
links:
- esi-nginx
depends_on:
- esi-nginx

api-image:
build: .
Expand All @@ -25,10 +38,10 @@ services:
- /app/src/node_modules
links:
- postgres
- redis
- esi-varnish
depends_on:
- postgres
- redis
- esi-varnish

updater:
command: yarn run start:updater
Expand All @@ -42,10 +55,10 @@ services:
- /app/src/node_modules
links:
- postgres
- redis
- esi-varnish
depends_on:
- postgres
- redis
- esi-varnish

killmails:
command: yarn run start:killmails
Expand All @@ -59,8 +72,8 @@ services:
- /app/src/node_modules
links:
- postgres
- redis
- esi-varnish
depends_on:
- postgres
- redis
- esi-varnish

1 change: 1 addition & 0 deletions example.env
Expand Up @@ -27,3 +27,4 @@ ESI_CLIENT=7sdf771c2casc8das8va78vasd
ESI_SECRET=Jb1b3j12jaskjdkjJjhk3jHJhs6Jkj456sdh3
ESI_REDIRECT=http://localhost:3000/authentication/sso/callback
ESI_SCOPE=publicData
ESI_ENDPOINT=https://esi.evetech.net/
6 changes: 6 additions & 0 deletions src/modules/core/external/esi/esi.interface.ts
Expand Up @@ -8,6 +8,12 @@ export enum Categories {
solar_system = 'solar_system',
}

export interface IGetStatus {
readonly players: number;
readonly server_version: string;
readonly start_time: Date;
}

export interface IGetAlliance {
readonly id: number;
readonly ticker: string;
Expand Down
16 changes: 15 additions & 1 deletion src/modules/core/external/esi/esi.service.ts
Expand Up @@ -11,6 +11,7 @@ import {
IUniverseCategory,
IUniverseGroup, IUniverseName,
IUniverseType,
IGetStatus,
} from './esi.interface';
import { ESIEntetyNotFoundException } from './esi.exceptions';
import { RequestContext } from '../../requestContext/requestContext';
Expand All @@ -19,7 +20,7 @@ import { LoggerService } from '../../logger/logger.service';
@Injectable()
export class ESIService {

private static baseUrl = 'https://esi.tech.ccp.is/latest/';
private static baseUrl = `${process.env.ESI_ENDPOINT}`;
private static userAgent = `eve-book/${process.env.npm_package_version}`
+ ` https://github.com/evebook/api`;
private client: AxiosInstance;
Expand All @@ -36,6 +37,19 @@ export class ESIService {
});
}

/**
* Get ESI Status
* @param query
* @return {Promise<ISearch>}
* @url https://esi.evetech.net/ui/#/Status
*/
public async status(): Promise<IGetStatus> {
return this.request<IGetStatus>({
url: 'status/',
method: 'GET',
});
}

/**
* Search for alliances, characters, corporations
* @param query
Expand Down
17 changes: 12 additions & 5 deletions src/modules/core/status/status.controller.ts
Expand Up @@ -4,21 +4,28 @@ import {
HttpStatus,
} from '@nestjs/common';
import { ApiResponse, ApiUseTags } from '@nestjs/swagger';
import { StatusService } from './status.service';
import { IStatus } from './status.interface';
import { DStatus } from './status.dto';

@ApiUseTags('status')
@Controller('status')
export class StatusController {

constructor(
private statusService: StatusService,
) {
}

@ApiResponse({
status: HttpStatus.OK,
type: { status: 'OK' },
type: DStatus,
description: 'API Status check',
})
@Get()
public async status() {
return {
status: 'OK',
};
public async status(): Promise<DStatus> {
const status = await this.statusService.status();
return new DStatus(status);
}

}
20 changes: 20 additions & 0 deletions src/modules/core/status/status.dto.ts
@@ -0,0 +1,20 @@
import { ApiModelProperty } from '@nestjs/swagger';
import { IStatus } from './status.interface';
import { IGetStatus } from '../external/esi/esi.interface';

export class DStatus {
@ApiModelProperty()
state: 'OK' | 'NOK';

@ApiModelProperty()
version: string;

@ApiModelProperty()
esi: IGetStatus;

constructor(status: IStatus) {
this.state = status.state;
this.version = status.version;
this.esi = status.esi;
}
}
7 changes: 7 additions & 0 deletions src/modules/core/status/status.interface.ts
@@ -0,0 +1,7 @@
import { IGetStatus } from '../external/esi/esi.interface';

export interface IStatus {
esi: IGetStatus;
state: 'OK' | 'NOK';
version: string;
}
11 changes: 11 additions & 0 deletions src/modules/core/status/status.module.ts
@@ -1,7 +1,18 @@
import { Module } from '@nestjs/common';
import { StatusController } from './status.controller';
import { ESIModule } from '../external/esi/esi.module';
import { StatusService } from './status.service';

@Module({
imports: [
ESIModule,
],
providers: [
StatusService,
],
exports: [
StatusService,
],
controllers: [
StatusController,
],
Expand Down
22 changes: 22 additions & 0 deletions src/modules/core/status/status.service.ts
@@ -0,0 +1,22 @@
import { Injectable, Inject } from '@nestjs/common';
import { ESIService } from '../external/esi/esi.service';
import { IStatus } from './status.interface';

@Injectable()
export class StatusService {

constructor(
private esiService: ESIService,
) {
}

async status(): Promise<IStatus> {
const esiStatus = await this.esiService.status();

return {
esi: esiStatus,
state: 'OK',
version: process.env.npm_package_version,
};
}
}

0 comments on commit 49eaebe

Please sign in to comment.