Skip to content

Commit

Permalink
Refactor things
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Oct 6, 2023
1 parent 7d686e0 commit 0a76982
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 27 deletions.
10 changes: 4 additions & 6 deletions .devcontainer/.docker/ipgeo/rootfs/etc/nginx/http.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 300s;

location / {
proxy_set_header traceparent "";
proxy_set_header tracestate "";
proxy_pass http://localhost:3000;
location = / {
return 302 /swagger/;
}

location /ipgeo/v2/ {
location / {
proxy_set_header traceparent "";
proxy_set_header tracestate "";
proxy_pass http://localhost:3000/;
proxy_pass http://localhost:3000;
}

location /swagger/ {
Expand Down
1 change: 0 additions & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ services:
- OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317
- OTEL_EXPORTER_OTLP_PROTOCOL=grpc
- OTEL_EXPORTER_OTLP_INSECURE=true
- HAVE_SWAGGER=true
- npm_config_userconfig=/usr/src/service/.npmrc.local
- GEOIP_CITY_FILE=/usr/share/GeoIP/GeoIP2-City.mmdb
- GEOIP_ISP_FILE=/usr/share/GeoIP/GeoIP2-ISP.mmdb
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@types/express": "^4.17.18",
"@types/mocha": "^10.0.2",
"@types/multer": "^1.4.8",
"@types/node": "^20.8.2",
"@types/node": "^20.8.3",
"@types/supertest": "^2.0.14",
"c8": "^8.0.1",
"chai": "^4.3.10",
Expand Down
12 changes: 3 additions & 9 deletions src/server.mts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ export function configureApp(app: Express): Promise<ReturnType<typeof initialize
}),
);

/* c8 ignore start */
if (process.env.HAVE_SWAGGER === 'true') {
app.get('/', (_req, res) => res.redirect('/swagger/'));
}
/* c8 ignore stop */

app.use(geoIPController(), notFoundMiddleware, errorMiddleware);
span.end();
return container;
Expand All @@ -57,17 +51,17 @@ export function configureApp(app: Express): Promise<ReturnType<typeof initialize
});
}

/* c8 ignore start */
export function setupApp(): Express {
export function createApp(): Express {
const app = express();
app.set('strict routing', true);
app.set('x-powered-by', false);
app.set('trust proxy', true);
return app;
}

/* c8 ignore start */
export async function run(): Promise<void> {
const app = setupApp();
const app = createApp();
const container = await configureApp(app);
const env = container.resolve('environment');

Expand Down
7 changes: 3 additions & 4 deletions test/functional/controller/geoip.test.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect } from 'chai';
import express, { type Express } from 'express';
import { type Express } from 'express';
import request from 'supertest';
import type { ErrorResponse } from '@myrotvorets/express-microservice-middlewares';
import { configureApp } from '../../../src/server.mjs';
import { configureApp, createApp } from '../../../src/server.mjs';
import { container } from '../../../src/lib/container.mjs';

describe('GeoIPController', function () {
Expand All @@ -23,8 +23,7 @@ describe('GeoIPController', function () {
GEOIP_ISP_FILE: join(base, '..', 'fixtures', 'GeoIP2-ISP-Test.mmdb'),
};

app = express();
app.set('trust proxy', true);
app = createApp();
return configureApp(app);
} finally {
process.env = { ...env };
Expand Down
5 changes: 3 additions & 2 deletions test/functional/controller/monitoring.test.mts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { expect } from 'chai';
import express, { type Express } from 'express';
import { type Express } from 'express';
import request from 'supertest';
import type { HealthChecker } from '@cloudnative/health-connect';
import { healthChecker, monitoringController } from '../../../src/controllers/monitoring.mjs';
import { createApp } from '../../../src/server.mjs';

describe('MonitoringController', function () {
let app: Express;

before(function () {
app = express();
app = createApp();
app.disable('x-powered-by');
app.use('/monitoring', monitoringController());
});
Expand Down

0 comments on commit 0a76982

Please sign in to comment.