Using Pact-Broker Behind Reverse Proxy And URL Rewrite in Kubernetes & Istio - url-rewriting

I deployed the pact-broker docker image (latest version) in a local Kubernetes cluster with the following deployment.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-pact-broker
...
spec:
containers:
- name: my-pact-broker
image: pactfoundation/pact-broker
ports:
- containerPort: 9292
env:
- name: PACT_BROKER_ALLOW_PUBLIC_READ
value: "true"
- name: PACT_BROKER_BASIC_AUTH_USERNAME
value: "****"
- name: PACT_BROKER_BASIC_AUTH_PASSWORD
value: "****
- name: PACT_BROKER_PORT
value: "9292"
- name: PACT_BROKER_LOG_LEVEL
value: "DEBUG"
- name: PACT_BROKER_SQL_LOG_LEVEL
value: "DEBUG"
...
An virtual service is configured for the istio ingress controller
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: my-pact-broker
namespace: default
spec:
.....
http:
- match:
- uri:
prefix: /pactbroker/
- uri:
prefix: /pactbroker
rewrite:
uri: /
route:
- destination:
port:
number: 9292
host: my-pact-broker.default.svc.cluster.local
headers:
request:
add:
X-Forwarded-Scheme: "https"
X-Forwarded-Host: "my-domain.com"
X-Forwarded-Port: "80"
The pact-broker api works fine. I successfully posted a pact to https://my-domain.com/pactbroker/pacts/provider/test-provider/consumer/test-consumer/version/1.0.0
The problem is with the pact-broker UI. When requesting https://my-domain.com/pactbroker the response is incomplete. The resources are pointing to root.
...
<body>
<link href='/stylesheets/index.css' rel='stylesheet'>
<link href='/stylesheets/material-menu.css' rel='stylesheet'>
<link href='/stylesheets/material-icon.css' rel='stylesheet'>
<link href='/stylesheets/jquery-confirm.min.css' rel='stylesheet'>
<script src='/javascripts/jquery.tablesorter.min.js' type='text/javascript'></script>
<script src='/javascripts/material-menu.js' type='text/javascript'></script>
<script src='/javascripts/index.js' type='text/javascript'></script>
<script src='/javascripts/clipboard.js' type='text/javascript'></script>
<script src='/javascripts/jquery-confirm.min.js' type='text/javascript'></script>
<div class='container'>
<nav class='navbase-default' id='navigation' role='navigation'>
<div class='container-fluid'>
<div class='navbar-header'></div>
<ul class='navbar-right' id='top-left-menu'>
<li>
<a href='?tags=true'>
Show latest tags
</a>
<a href='/hal-browser/browser.html'>
API Browser
</a>
</li>
</ul>
</div>
</nav>
....
The HAL-Browser has a similar problem:
The references in the URI Template are not showing the uri prefix "pactbroker"
https://my-domain.org/pacts/provider//consumer//version/
What do I have to do to make this work correctly.

I found the missing information in the Changelog of the pact-broker project.
Adding the environment variable PACT_BROKER_BASE_URL fixed the issue
- name: "PACT_BROKER_BASE_URL"
value: "https://my-domain.com/pactbroker"

Related

how to use static schema by swagger?

can`t render schema. got this error:
Unable to render this definition The provided definition does not
specify a valid version field.
Please indicate a valid Swagger or OpenAPI version field. Supported
version fields are swagger: "2.0" and those that match openapi: 3.0.n
(for example, openapi: 3.0.0).
Hi! i need to use my static schema, and trying to render this template(from django doc).
but it has not worked
urlpatterns = [
path('swagger/', TemplateView.as_view(
template_name='api_documentations/swagger.html',
), name='swagger'),
html template:
<!DOCTYPE html>
{% load static %}
<html>
<head>
<title>Swagger</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="//unpkg.com/swagger-ui-dist#3/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="//unpkg.com/swagger-ui-dist#3/swagger-ui-bundle.js"></script>
<script>
const ui = SwaggerUIBundle({
swagger: "2.1",
url: "{% static 'static-docs/api/openapi.schema' %}",
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
],[enter image description here][1]
layout: "BaseLayout",
requestInterceptor: (request) => {
request.headers['X-CSRFToken'] = "{{ csrf_token }}"
return request;
}
})
</script>
</body>
</html>

livewire does not update variable after xhr

Description:
the 2 way data binding does not work, the value of the variable doesn't update.
Exact steps to reproduce
clean laravel installtaion
livewire install
livewire:make test
Stripped-down, copy-pastable code snippets
livewire/Test.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Test extends Component
{
public $text;
public function render()
{
return view('livewire.test');
}
}
livewire/test.blade.php
<input type="text" wire:model="text">
{{$text}}
welcome.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght#400;600;700&display=swap" rel="stylesheet">
<livewire:styles />
<style>
body {
font-family: 'Nunito';
}
</style>
</head>
<body class="antialiased">
<livewire:test/>
<livewire:scripts />
</body>
</html>
Request Ppayload
{fingerprint: {id: "p2OSso56TqMjMT4XN4Oo", name: "test", locale: "en"},…}
fingerprint: {id: "p2OSso56TqMjMT4XN4Oo", name: "test", locale: "en"}
id: "p2OSso56TqMjMT4XN4Oo"
locale: "en"
name: "test"
serverMemo: {children: [], errors: [], htmlHash: "b6eb143a", data: {text: "te"}, dataMeta: [],…}
checksum: "1949b7cded0c349a39cb3f8d9d36a92bd88d5c3a1b676544851ddd229d157c4c"
children: []
data: {text: "te"}
text: "te"
dataMeta: []
errors: []
htmlHash: "b6eb143a"
updates: [{type: "syncInput", payload: {name: "text", value: "test"}}]
0: {type: "syncInput", payload: {name: "text", value: "test"}}
payload: {name: "text", value: "test"}
name: "text"
value: "test"
type: "syncInput"
Context
Livewire version: 2.2
Laravel version: 8.10
Browser: [Edge, Chrome, Opera]
As already written by Qirel your test.blade.php must only have one single root element like this
<div>
<input type="text" wire:model="text">
{{$text}}
</div>

How to avoid CORS origin error with docker and elastic search image

I contrived to bypass the CORS origin error client side by setting up an apache web server with docker so as to use modules. Nevertheless, when I add elasticsearch service to my docker-compose and I try to get my json response from it I still have it. It says "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9200/"
my docker-compose :
version: '2'
services:
apache:
image: 'bitnami/apache:latest'
ports:
- '80:8080'
- '443:8443'
volumes:
- .:/app
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
volumes:
data01:
driver: local
networks:
elastic:
driver: bridge
my index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
</head>
<body>
<div class="home">
<h5>Elastic home</h5>
<p> Cluster name:</p>
<p id="cluster_name"></p>
<p> Cluster version: </p>
<p id="cluster_version"></p>
</div>
<link rel="stylesheet" href="style.css">
<script type="application/javascript">
fetch('http://localhost:9200')
.then(async (response) => {
let data = await response.json()
document.getElementById('cluster_name').innerText = data.cluster_name
document.getElementById('cluster_version').innerText = data.version.number
})
</script>
</body>
</html>
I found out how, I changed my environment elastic service to
environment:
- discovery.type=single-node
- node.name=es01
- cluster.name=es-docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- http.host=0.0.0.0
- http.port=9200
- "http.cors.allow-origin=http://localhost"
- "http.cors.enabled=true"
- "http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization"
- "http.cors.allow-credentials=true"

Angular2 in visual studio 2017 : run error (Resource not found)

I followed this: https://www.codeproject.com/Articles/1181888/Angular-in-ASP-NET-MVC-Web-API-Part
Error:
My URL - - - > http://localhost/home
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /home
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.7.2110.0
systemjs.config.js
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
'app': 'app',
// angular bundles
'#angular/core': 'npm:#angular/core/bundles/core.umd.js',
'#angular/common': 'npm:#angular/common/bundles/common.umd.js',
'#angular/compiler': 'npm:#angular/compiler/bundles/compiler.umd.js',
'#angular/platform-browser': 'npm:#angular/platform-browser/bundles/platform-browser.umd.js',
'#angular/platform-browser-dynamic': 'npm:#angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'#angular/http': 'npm:#angular/http/bundles/http.umd.js',
'#angular/router': 'npm:#angular/router/bundles/router.umd.js',
'#angular/forms': 'npm:#angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: 'main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
appcomponent
import { Component } from "#angular/core"
#Component({
selector: "user-app",
template: `
<div>
<nav class='navbar navbar-inverse'>
<div class='container-fluid'>
<ul class='nav navbar-nav'>
<li><a [routerLink]="['home']">Home</a></li>
</ul>
</div>
</nav>
<div class='container'>
<router-outlet></router-outlet>
</div>
</div>
`
})
export class AppComponent {
}
app.routing
import { ModuleWithProviders } from '#angular/core';
import { Routes, RouterModule } from '#angular/router';
import { HomeComponent } from './Components/home.component';
const appRoutes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
app.module
import { platformBrowserDynamic } from '#angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
_layout.cshtml
<!DOCTYPE html>
<html>
<head>
<base href="/" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#ViewBag.Title - My ASP.NET Application</title>
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
<script src="/node_modules/core-js/client/shim.min.js"></script>
<script src="/node_modules/zone.js/dist/zone.js"></script>
<script src="/node_modules/systemjs/dist/system.src.js"></script>
<script src="/systemjs.config.js"></script>
<script src="../node_modules/angular2/bundles/router.dev.js"></script>
<script>
System.import('app/main.js').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<div class="container body-content">
#RenderBody()
<hr />
<footer>
<p>© #DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/bootstrap")
#RenderSection("scripts", required: false)
</body>
</html>
Need support please
in your systemjs.config.js change 'npm:': 'node_modules/' to 'npm:': '/node_modules/'
No issues in the code. All good. I was requesting a wrong url.
Also one small change in system.config.js
Instead of 'npm:': 'node_modules/', we need to use 'npm:': '/node_modules/'

Symfony2 theming

I want basic theming support in my Symfony2 project, so I wanted to have separated static files (css, js, img) for each theme.
I have tried to add
assetic:
read_from: %kernel.root_dir%/../web/themes/mytheme
but this took no effect, my {{ asset('css/style.css') }} are still referencing realtic to %kernel.root_dir%/../web, instead %kernel.root_dir%/../web/themes/mytheme.
Any idea?
Fixed with config:
assetic:
debug: %kernel.debug%
use_controller: false
read_from: %kernel.root_dir%/../web/bundles/mybundle/themes/%my_theme%
write_to: %kernel.root_dir%/../web
filters:
yui_css:
jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
yui_js:
jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
And in layout I have:
{% stylesheets 'css/*' filter='?yui_css' %}
<link rel="stylesheet" type="text/css" media="all" href="{{ asset_url }}" />
{% endstylesheets %}

Resources