Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSR/CSR api tweaks #438

Merged
merged 2 commits into from
Aug 28, 2024
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
2 changes: 2 additions & 0 deletions packages/server/src/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { buildHtmlElementString } from "./lib/html-element-string-builder";
import { unsafeHtml } from "decorator-shared/html";
import { HtmlElementProps } from "decorator-shared/types";
import { buildCdnUrl } from "./urls";
import { cssLink } from "./views/styles";

// Assets from public folder
const faviconIco = "favicon.ico";
Expand All @@ -10,6 +11,7 @@ const appleTouchIcon = "apple-touch-icon.png";
const webManifest = "site2.webmanifest";

export const headAssets: HtmlElementProps[] = [
cssLink,
{
tag: "link",
attribs: {
Expand Down
3 changes: 1 addition & 2 deletions packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ app.get("/footer", async ({ req, html }) => {
);
});
app.get("/ssr", ssrApiHandler);
// /env is used for CSR
// TODO: The CSR implementation can probably be tweaked to use the same data as /ssr
app.get("/env", async ({ req, json }) => {
app.on("GET", ["/env", "/csr"], async ({ req, json }) => {
const params = validParams(req.query());
const features = getFeatures();

Expand Down
18 changes: 10 additions & 8 deletions packages/server/src/views/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ export const getCSSUrl = async () => {
return buildCdnUrl(manifest["src/main.ts"].css[0]);
};

export const cssLink = {
tag: "link",
attribs: {
type: "text/css",
rel: "stylesheet",
href: await getCSSUrl(),
},
};

const getCssElementAsString = async () => {
if (env.NODE_ENV === "development") {
return "<!-- non-empty css response to make nav-dekoratoren-moduler happy -->";
}

return buildHtmlElementString({
tag: "link",
attribs: {
type: "text/css",
rel: "stylesheet",
href: await getCSSUrl(),
},
});
return buildHtmlElementString(cssLink);
};

const cssHtml = unsafeHtml(await getCssElementAsString());
Expand Down
Loading