Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ see wiki for more information: [wiki](https://github.com/thmarx/cms/wiki)
* **FEATURE** Add redirect support for aliases [454](https://github.com/CondationCMS/cms-server/issues/454)
* **FEATURE** Signature for modules and themes [471](https://github.com/CondationCMS/cms-server/issues/471)
* **FEATURE** Switch password has to secure algorithm [472](https://github.com/CondationCMS/cms-server/issues/472)
* **FEATURE** Add spa mode for sites [476](https://github.com/CondationCMS/cms-server/issues/476)

### Developer experience

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ public interface SiteProperties {
public String templateEngine();

public List<String> activeModules();

public default boolean spaEnabled () {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public boolean cacheContent() {
return configuration.getBoolean("cache.content", Constants.DEFAULT_CONTENT_CACHE_ENABLED);
}

@Override
public boolean spaEnabled() {
return configuration.getBoolean("spa.enabled", false);
}

@Override
public String templateEngine() {
return configuration.getString("template.engine");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
*/


import com.condation.cms.api.configuration.configs.SiteConfiguration;
import com.condation.cms.api.content.ContentResponse;
import com.condation.cms.api.content.DefaultContentResponse;
import com.condation.cms.api.content.RedirectContentResponse;
import com.condation.cms.api.feature.features.ConfigurationFeature;
import com.condation.cms.api.request.RequestContext;
import com.condation.cms.api.utils.HTTPUtil;
import com.condation.cms.api.utils.RequestUtil;
Expand Down Expand Up @@ -62,6 +64,14 @@ public boolean handle(Request request, Response response, Callback callback) thr
var queryParameters = HTTPUtil.queryParameters(request.getHttpURI().getQuery());
var requestContext = (RequestContext) request.getAttribute(CreateRequestContextFilter.REQUEST_CONTEXT);

// handle enabled spa mode
var spaEnabled = requestContext.get(ConfigurationFeature.class).configuration().get(SiteConfiguration.class).siteProperties().spaEnabled();
var notFoundContent = "/.technical/404";
if (spaEnabled) {
uri = "";
notFoundContent = "/";
}

try {
Optional<ContentResponse> content = contentResolver.getContent(requestContext);
response.setStatus(200);
Expand All @@ -73,7 +83,7 @@ public boolean handle(Request request, Response response, Callback callback) thr
if (content.isEmpty()) {
log.debug("content not found {}", uri);
try (var errorContext = requestContextFactory.create(request.getContext().getContextPath(),
"/.technical/404",
notFoundContent,
queryParameters, Optional.of(request))) {
content = contentResolver.getErrorContent(errorContext);
response.setStatus(404);
Expand Down
14 changes: 14 additions & 0 deletions test-server/hosts/demo_spa/assets/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
font-family: sans-serif;
padding: 2rem;
}

nav a {
margin-right: 1rem;
text-decoration: none;
color: steelblue;
}

nav a:hover {
text-decoration: underline;
}
30 changes: 30 additions & 0 deletions test-server/hosts/demo_spa/assets/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const routes = {
"/": () => "<h1>Welcome!</h1><p>This is the starting page.</p>",
"/about": () => "<h1>About us</h1><p>We are the team behind CondationCMS.</p>",
"/contact": () => "<h1>Contact</h1><p>Send us a message!</p>",
};

function router() {
const path = window.location.pathname;
const content = routes[path] ? routes[path]() : "<h1>404</h1><p>Seite nicht gefunden</p>";
document.getElementById("app").innerHTML = content;
}

function navigateTo(url) {
history.pushState(null, null, url);
router();
}

// Link-Klicks abfangen
document.addEventListener("click", e => {
if (e.target.matches("[data-link]")) {
e.preventDefault();
navigateTo(e.target.href);
}
});

// Popstate (zurück/vor)
window.addEventListener("popstate", router);

// Initialer Aufruf
document.addEventListener("DOMContentLoaded", router);
10 changes: 10 additions & 0 deletions test-server/hosts/demo_spa/content/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Startseite
template: index.html
search:
index: false
---

# Demo Project

![TestBild!](/media/images/test.jpg?format=small)
1 change: 1 addition & 0 deletions test-server/hosts/demo_spa/site-dev.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hostname = [ "localhost5" ]
7 changes: 7 additions & 0 deletions test-server/hosts/demo_spa/site.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id = "demo-spa"
hostname = [ "localhost2" ]
baseurl = "http://localhosts:2020"
language = "en"

[spa]
enabled = true
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions test-server/hosts/demo_spa/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Mini SPA</title>
<link rel="stylesheet" href="/assets/app.css" />
</head>
<body>
<nav>
<a href="/" data-link>Home</a>
<a href="/about" data-link>About us</a>
<a href="/contact" data-link>Contact</a>
</nav>

<main id="app">
<!-- content gets rendered here -->
</main>

<script src="/assets/app.js"></script>
</body>
</html>

4 changes: 0 additions & 4 deletions test-server/hosts/features/assets/app-1.js

This file was deleted.

3 changes: 0 additions & 3 deletions test-server/hosts/features/assets/form-1.css

This file was deleted.

50 changes: 0 additions & 50 deletions test-server/hosts/features/assets/form-1.js

This file was deleted.

Binary file removed test-server/hosts/features/assets/images/test.jpg
Binary file not shown.

This file was deleted.

1 change: 0 additions & 1 deletion test-server/hosts/features/assets/styles-1.css

This file was deleted.

4 changes: 0 additions & 4 deletions test-server/hosts/features/config/auth.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions test-server/hosts/features/config/forms.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions test-server/hosts/features/config/taxonomy.tags.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions test-server/hosts/features/config/taxonomy.yaml

This file was deleted.

1 change: 0 additions & 1 deletion test-server/hosts/features/config/users.realm

This file was deleted.

5 changes: 0 additions & 5 deletions test-server/hosts/features/content/.technical/404.md

This file was deleted.

5 changes: 0 additions & 5 deletions test-server/hosts/features/content/.technical/test/example.md

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions test-server/hosts/features/content/blog/2023-09/new-post.md

This file was deleted.

7 changes: 0 additions & 7 deletions test-server/hosts/features/content/blog/2023-10/new-post.md

This file was deleted.

9 changes: 0 additions & 9 deletions test-server/hosts/features/content/blog/index.md

This file was deleted.

9 changes: 0 additions & 9 deletions test-server/hosts/features/content/contact/index.md

This file was deleted.

9 changes: 0 additions & 9 deletions test-server/hosts/features/content/content-editing/index.md

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading