mirror of
https://github.com/Nutomic/ibis.git
synced 2024-12-23 15:51:24 +00:00
Never use https in SSR mode, some more bug fixes
This commit is contained in:
parent
7f85248799
commit
1c5229430f
6 changed files with 41 additions and 41 deletions
11
build.rs
11
build.rs
|
@ -1,13 +1,20 @@
|
|||
use std::{
|
||||
fs::{create_dir_all, File},
|
||||
io::Result,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
/// Create placeholders for wasm files so that `cargo check` etc work without explicitly building
|
||||
/// frontend.
|
||||
fn main() -> Result<()> {
|
||||
create_dir_all("assets/dist/")?;
|
||||
File::create("assets/dist/ibis.js")?;
|
||||
File::create("assets/dist/ibis_bg.wasm")?;
|
||||
let js = "assets/dist/ibis.js";
|
||||
if !Path::new(js).exists() {
|
||||
File::create(js)?;
|
||||
}
|
||||
let wasm = "assets/dist/ibis_bg.wasm";
|
||||
if !Path::new(wasm).exists() {
|
||||
File::create(wasm)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -32,11 +32,35 @@ use url::Url;
|
|||
pub struct ApiClient {
|
||||
client: Client,
|
||||
pub hostname: String,
|
||||
ssl: bool,
|
||||
}
|
||||
|
||||
impl ApiClient {
|
||||
pub fn new(client: Client, hostname: String) -> Self {
|
||||
Self { client, hostname }
|
||||
pub fn new(client: Client, hostname_: Option<String>) -> Self {
|
||||
let mut hostname;
|
||||
let ssl;
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
{
|
||||
hostname = web_sys::window().unwrap().location().host().unwrap();
|
||||
ssl = !cfg!(debug_assertions);
|
||||
}
|
||||
#[cfg(feature = "ssr")]
|
||||
{
|
||||
hostname = crate::backend::config::IbisConfig::read()
|
||||
.unwrap()
|
||||
.bind
|
||||
.to_string();
|
||||
ssl = false;
|
||||
}
|
||||
// required for tests
|
||||
if let Some(hostname_) = hostname_ {
|
||||
hostname = hostname_;
|
||||
}
|
||||
Self {
|
||||
client,
|
||||
hostname,
|
||||
ssl,
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_query<T, R>(&self, endpoint: &str, query: Option<R>) -> MyResult<T>
|
||||
|
@ -203,7 +227,8 @@ impl ApiClient {
|
|||
}
|
||||
|
||||
fn request_endpoint(&self, path: &str) -> String {
|
||||
format!("{}://{}{path}", http_protocol_str(), &self.hostname)
|
||||
let protocol = if self.ssl { "https" } else { "http" };
|
||||
format!("{protocol}://{}{path}", &self.hostname)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ use crate::{
|
|||
common::LocalUserView,
|
||||
frontend::{
|
||||
api::ApiClient,
|
||||
backend_hostname,
|
||||
components::nav::Nav,
|
||||
pages::{
|
||||
article::{
|
||||
|
@ -81,11 +80,9 @@ impl GlobalState {
|
|||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
let backend_hostname = backend_hostname();
|
||||
|
||||
provide_meta_context();
|
||||
let backend_hostname = GlobalState {
|
||||
api_client: ApiClient::new(Client::new(), backend_hostname.clone()),
|
||||
api_client: ApiClient::new(Client::new(), None),
|
||||
my_profile: None,
|
||||
};
|
||||
// Load user profile in case we are already logged in
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::frontend::backend_hostname;
|
||||
use markdown_it::{
|
||||
parser::inline::{InlineRule, InlineState},
|
||||
MarkdownIt,
|
||||
|
@ -26,12 +25,7 @@ impl NodeValue for ArticleLink {
|
|||
fn render(&self, node: &Node, fmt: &mut dyn Renderer) {
|
||||
let mut attrs = node.attrs.clone();
|
||||
|
||||
let local = backend_hostname() == self.domain;
|
||||
let link = if local {
|
||||
format!("/article/{}", self.title)
|
||||
} else {
|
||||
format!("/article/{}@{}", self.title, self.domain)
|
||||
};
|
||||
let link = format!("/article/{}@{}", self.title, self.domain);
|
||||
attrs.push(("href", link));
|
||||
|
||||
fmt.open("a", &attrs);
|
||||
|
@ -68,14 +62,7 @@ impl InlineRule for ArticleLinkScanner {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_markdown_local_article_link() {
|
||||
let parser = markdown_parser();
|
||||
let rendered = parser.parse("[[Title@127.0.0.1:8081]]").render();
|
||||
assert_eq!("<p><a href=\"/article/Title\">Title</a></p>\n", rendered);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_markdown_remote_article_link() {
|
||||
fn test_markdown_article_link() {
|
||||
let parser = markdown_parser();
|
||||
let rendered = parser.parse("[[Title@example.com]]").render();
|
||||
assert_eq!(
|
||||
|
|
|
@ -47,19 +47,3 @@ fn user_link(person: &DbPerson) -> impl IntoView {
|
|||
<a href={creator_path}>{user_title(person)}</a>
|
||||
}
|
||||
}
|
||||
|
||||
fn backend_hostname() -> String {
|
||||
let backend_hostname;
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
{
|
||||
backend_hostname = web_sys::window().unwrap().location().host().unwrap();
|
||||
}
|
||||
#[cfg(feature = "ssr")]
|
||||
{
|
||||
backend_hostname = crate::backend::config::IbisConfig::read()
|
||||
.unwrap()
|
||||
.bind
|
||||
.to_string();
|
||||
}
|
||||
backend_hostname
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ impl IbisInstance {
|
|||
password: "hunter2".to_string(),
|
||||
};
|
||||
let client = ClientBuilder::new().cookie_store(true).build().unwrap();
|
||||
let api_client = ApiClient::new(client, hostname.clone());
|
||||
let api_client = ApiClient::new(client, Some(hostname));
|
||||
api_client.register(form).await.unwrap();
|
||||
Self {
|
||||
api_client,
|
||||
|
|
Loading…
Reference in a new issue