Skip to content

Commit

Permalink
Merge pull request #637 from thoth-pub/feature/636_fix_duplicate_prot…
Browse files Browse the repository at this point in the history
…ocol

Feature/636 fix duplicate protocol
  • Loading branch information
ja573 authored Oct 15, 2024
2 parents e4a3b59 + 9bb0dd0 commit a560921
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- [636](https://github.com/thoth-pub/thoth/issues/636) - OpenAPI documentation was displaying the public URL of the export API with an extra protocol

## [[0.12.11]](https://github.com/thoth-pub/thoth/releases/tag/v0.12.11) - 2024-10-14
### Changed
Expand Down
16 changes: 14 additions & 2 deletions thoth-export-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::time::Duration;
use actix_cors::Cors;
use actix_web::{middleware::Logger, web::Data, App, HttpServer};
use paperclip::actix::{web, web::HttpResponse, OpenApiExt};
use paperclip::v2::models::{Contact, DefaultApiRaw, Info, License, Tag};
use paperclip::v2::models::{Contact, DefaultApiRaw, Info, License, OperationProtocol, Tag};
use thoth_client::ThothClient;

mod bibtex;
Expand Down Expand Up @@ -56,8 +56,20 @@ pub async fn start_server(
log::info!("Setting Thoth GraphQL endpoint to {}", gql_endpoint);

HttpServer::new(move || {
// extract hostname and protocol from public URL
let (protocol, host) = public_url
.strip_prefix("https://")
.map(|stripped| (OperationProtocol::Https, stripped))
.or_else(|| {
public_url
.strip_prefix("http://")
.map(|stripped| (OperationProtocol::Http, stripped))
})
.unwrap_or((OperationProtocol::Http, public_url.as_str()));

let spec = DefaultApiRaw {
host: Some(public_url.clone()),
host: Some(host.to_string()),
schemes: [protocol].into_iter().collect(),
tags: vec![
Tag {
name: "Formats".to_string(),
Expand Down

0 comments on commit a560921

Please sign in to comment.