Skip to content

Commit

Permalink
SC-16584: Update of swagger-ui image and Glue Infrastructure preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
fsmeier committed Oct 10, 2023
1 parent 6a94e22 commit 69abab8
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 2 deletions.
70 changes: 70 additions & 0 deletions bin/standalone/cli-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,76 @@ class Dispatcher {
response.end();
});
}

_options_glueStorefrontSchema(request, response) {
response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Allow-Methods', 'GET');
response.statusCode = 201;
response.end();
}

_get_glueStorefrontSchema(request, response) {
const fileLocation = process.env.SPRYKER_REST_API_SCHEMA_PATH || 'src/Generated/Storefront/Specification/spryker_storefront_api.schema.yml';
const baseUrl = request.headers['x-schema-base-url'] || '';

fs.readFile(process.env.PWD + '/' + fileLocation, 'utf8', function (error,schemaContent) {

response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Allow-Methods', 'GET');

if (error) {
response.setHeader('Content-Type', 'text/plain');
response.statusCode = 500;
response.write(error.toString());
response.end();
return;
}

if (baseUrl !== '') {
schemaContent = schemaContent.replace(/(servers:\s*-\s*url:\s*['"])[^'"]*?(['"])/gm, '$1' + baseUrl + '$2');
}

response.setHeader('Content-Type', 'text/yaml');
response.statusCode = 200;
response.write(schemaContent);
response.end();
});
}

_options_glueBackendSchema(request, response) {
response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Allow-Methods', 'GET');
response.statusCode = 201;
response.end();
}

_get_glueBackendSchema(request, response) {
const fileLocation = process.env.SPRYKER_REST_API_SCHEMA_PATH || 'src/Generated/GlueBackend/Specification/spryker_backend_api.schema.yml';
const baseUrl = request.headers['x-schema-base-url'] || '';

fs.readFile(process.env.PWD + '/' + fileLocation, 'utf8', function (error,schemaContent) {

response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Allow-Methods', 'GET');

if (error) {
response.setHeader('Content-Type', 'text/plain');
response.statusCode = 500;
response.write(error.toString());
response.end();
return;
}

if (baseUrl !== '') {
schemaContent = schemaContent.replace(/(servers:\s*-\s*url:\s*['"])[^'"]*?(['"])/gm, '$1' + baseUrl + '$2');
}

response.setHeader('Content-Type', 'text/yaml');
response.statusCode = 200;
response.write(schemaContent);
response.end();
});
}
}

class Server {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
{% extends "nginx/http/gateway/server.conf.twig" %}
{% block locations %}
{{ parent() }}
location /schema.yml {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-SCHEMA-BASE-URL $scheme://$host;

resolver 127.0.0.11 valid=10s;
set $cli_proxy_pass http://cli:9000/glueBackendSchema/;
proxy_pass $cli_proxy_pass;
}
{% endblock locations %}
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
{% include 'nginx/http/gateway/glue.server.conf.twig' with _context %}
{% extends "nginx/http/gateway/server.conf.twig" %}
{% block locations %}
{{ parent() }}
location /schema.yml {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-SCHEMA-BASE-URL $scheme://$host;

resolver 127.0.0.11 valid=10s;
set $cli_proxy_pass http://cli:9000/glueStorefrontSchema/;
proxy_pass $cli_proxy_pass;
}
{% endblock locations %}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{% include "service/#{engine}/v3.24/#{engine}.yml.twig" with _context only %}
{% include "service/#{engine}/v5.9/#{engine}.yml.twig" with _context only %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% set protocol = project['docker']['ssl']['enabled'] ? 'https://' : 'http://' %}
{% set firstGlueEndpointMap = project['_endpointMap'] | first %}
{{ serviceName }}:
image: swaggerapi/swagger-ui:v5.9.0
networks:
- private
labels:
'spryker.app.name': swagger
'spryker.app.type': hidden
'spryker.project': ${SPRYKER_DOCKER_PREFIX}:${SPRYKER_DOCKER_TAG}
environment:
URLS: "[{ url: \"{{ protocol ~ firstGlueEndpointMap['glue'] }}/schema.yml\", name: \"(Old) Glue API\" }]"
healthcheck:
test: [ "CMD", "nc", "-z", "localhost", "8080" ]
interval: 5s
timeout: 5s
retries: 5

0 comments on commit 69abab8

Please sign in to comment.