joinlemmy-site/src/server/index.tsx

116 lines
3.7 KiB
TypeScript
Raw Permalink Normal View History

New tailwind-based joinlemmy-site (#243) * Starting on new tailwind based joinlemmy-site. * Formatting fix. * Adding follow communities block. * Adding a few more blocks. * Finishing up blocks. * Adding a few more pages. * Adding apps page. * Almost done with donation page. * Adding most of instances page. * Trying to fix CI 1. * Adding navbar and footer. * Adding bottom spacer. * Finishing up more info modal. * Adding icons to main page. * Eruda only in development mode. * Finishing up main page, starting to work on recs. * Adding main images. * Adding images 2. * Starting to add filters. * Finishing up helper modal. * Adding topic icons. * Adding more instances. * Fixing recommended. * Forgot to add instance picker. * Adding world background image. * Adding alexandrite. * Adding funding goal block. * Fix dockerfile. * Upgrading deps. * Fixing package json. * Updating coders, sponsors. * Fixing mobile margins. * Fixing navbar auto-close when clicked. * Removing todo. * Removing some useless instance helper links. * Fixing news titling. * Addressing PR comments. * Updating instance stats. * Fixing class -> className * Fixing sm:max directives. * Make instance images links to their sites. * Use ubuntu font. * Addressing PR comments. * Adding a few more android apps. * Adding thunder and combustible apps. * Fixing z index. * Add a warning alert for closed source apps. * Adding MLMYM app. Fixes #213 * Fixing i18n key. * Adding QR codes for cryptos. Fixes #219 * Addressing PR comments. * Fixing news preview. * Adding registration mode to details modal. Fixes #153 * Filter out bot instances. * Using glide carousel. * Adding glide min css. * Adding donation platform fetching. Fixes #248 * Prettying glide css. * Change dev goal to 3 * Adding sign up button. * Minifying docker image. * Removing sortpack.
2023-10-31 13:31:03 +00:00
import express, { RequestHandler, Request, Response } from "express";
import { StaticRouter } from "inferno-router";
import { renderToString } from "inferno-server";
// import { matchPath } from "inferno-router";
import path from "path";
import { App } from "../shared/components/app";
// import { routes } from "../shared/routes";
import process from "process";
import { Helmet } from "inferno-helmet";
import { getLanguageFromCookie, i18n } from "../shared/i18next";
const server = express();
const port = 1234;
server.use(express.json() as RequestHandler);
server.use(express.urlencoded({ extended: false }) as RequestHandler);
server.use("/static", express.static(path.resolve("./dist")));
server.use("/docs", express.static(path.resolve("./dist/assets/docs")));
server.use("/api", express.static(path.resolve("./dist/assets/api")));
server.use(
"/context.json",
express.static(path.resolve("./dist/assets/lemmy_federation_context.json")),
);
server.use("/feed.xml", express.static(path.resolve("./dist/feed.xml")));
New tailwind-based joinlemmy-site (#243) * Starting on new tailwind based joinlemmy-site. * Formatting fix. * Adding follow communities block. * Adding a few more blocks. * Finishing up blocks. * Adding a few more pages. * Adding apps page. * Almost done with donation page. * Adding most of instances page. * Trying to fix CI 1. * Adding navbar and footer. * Adding bottom spacer. * Finishing up more info modal. * Adding icons to main page. * Eruda only in development mode. * Finishing up main page, starting to work on recs. * Adding main images. * Adding images 2. * Starting to add filters. * Finishing up helper modal. * Adding topic icons. * Adding more instances. * Fixing recommended. * Forgot to add instance picker. * Adding world background image. * Adding alexandrite. * Adding funding goal block. * Fix dockerfile. * Upgrading deps. * Fixing package json. * Updating coders, sponsors. * Fixing mobile margins. * Fixing navbar auto-close when clicked. * Removing todo. * Removing some useless instance helper links. * Fixing news titling. * Addressing PR comments. * Updating instance stats. * Fixing class -> className * Fixing sm:max directives. * Make instance images links to their sites. * Use ubuntu font. * Addressing PR comments. * Adding a few more android apps. * Adding thunder and combustible apps. * Fixing z index. * Add a warning alert for closed source apps. * Adding MLMYM app. Fixes #213 * Fixing i18n key. * Adding QR codes for cryptos. Fixes #219 * Addressing PR comments. * Fixing news preview. * Adding registration mode to details modal. Fixes #153 * Filter out bot instances. * Using glide carousel. * Adding glide min css. * Adding donation platform fetching. Fixes #248 * Prettying glide css. * Change dev goal to 3 * Adding sign up button. * Minifying docker image. * Removing sortpack.
2023-10-31 13:31:03 +00:00
function erudaInit(): string {
if (process.env["NODE_ENV"] == "development") {
return `
<script src="//cdn.jsdelivr.net/npm/eruda"></script>
<script>eruda.init();</script>
`;
} else {
return "";
}
}
New tailwind-based joinlemmy-site (#243) * Starting on new tailwind based joinlemmy-site. * Formatting fix. * Adding follow communities block. * Adding a few more blocks. * Finishing up blocks. * Adding a few more pages. * Adding apps page. * Almost done with donation page. * Adding most of instances page. * Trying to fix CI 1. * Adding navbar and footer. * Adding bottom spacer. * Finishing up more info modal. * Adding icons to main page. * Eruda only in development mode. * Finishing up main page, starting to work on recs. * Adding main images. * Adding images 2. * Starting to add filters. * Finishing up helper modal. * Adding topic icons. * Adding more instances. * Fixing recommended. * Forgot to add instance picker. * Adding world background image. * Adding alexandrite. * Adding funding goal block. * Fix dockerfile. * Upgrading deps. * Fixing package json. * Updating coders, sponsors. * Fixing mobile margins. * Fixing navbar auto-close when clicked. * Removing todo. * Removing some useless instance helper links. * Fixing news titling. * Addressing PR comments. * Updating instance stats. * Fixing class -> className * Fixing sm:max directives. * Make instance images links to their sites. * Use ubuntu font. * Addressing PR comments. * Adding a few more android apps. * Adding thunder and combustible apps. * Fixing z index. * Add a warning alert for closed source apps. * Adding MLMYM app. Fixes #213 * Fixing i18n key. * Adding QR codes for cryptos. Fixes #219 * Addressing PR comments. * Fixing news preview. * Adding registration mode to details modal. Fixes #153 * Filter out bot instances. * Using glide carousel. * Adding glide min css. * Adding donation platform fetching. Fixes #248 * Prettying glide css. * Change dev goal to 3 * Adding sign up button. * Minifying docker image. * Removing sortpack.
2023-10-31 13:31:03 +00:00
function setLanguage(req: Request, res: Response): string {
// Setting the language for non-js browsers
const cookieLang = getLanguageFromCookie(req.headers.cookie);
New tailwind-based joinlemmy-site (#243) * Starting on new tailwind based joinlemmy-site. * Formatting fix. * Adding follow communities block. * Adding a few more blocks. * Finishing up blocks. * Adding a few more pages. * Adding apps page. * Almost done with donation page. * Adding most of instances page. * Trying to fix CI 1. * Adding navbar and footer. * Adding bottom spacer. * Finishing up more info modal. * Adding icons to main page. * Eruda only in development mode. * Finishing up main page, starting to work on recs. * Adding main images. * Adding images 2. * Starting to add filters. * Finishing up helper modal. * Adding topic icons. * Adding more instances. * Fixing recommended. * Forgot to add instance picker. * Adding world background image. * Adding alexandrite. * Adding funding goal block. * Fix dockerfile. * Upgrading deps. * Fixing package json. * Updating coders, sponsors. * Fixing mobile margins. * Fixing navbar auto-close when clicked. * Removing todo. * Removing some useless instance helper links. * Fixing news titling. * Addressing PR comments. * Updating instance stats. * Fixing class -> className * Fixing sm:max directives. * Make instance images links to their sites. * Use ubuntu font. * Addressing PR comments. * Adding a few more android apps. * Adding thunder and combustible apps. * Fixing z index. * Add a warning alert for closed source apps. * Adding MLMYM app. Fixes #213 * Fixing i18n key. * Adding QR codes for cryptos. Fixes #219 * Addressing PR comments. * Fixing news preview. * Adding registration mode to details modal. Fixes #153 * Filter out bot instances. * Using glide carousel. * Adding glide min css. * Adding donation platform fetching. Fixes #248 * Prettying glide css. * Change dev goal to 3 * Adding sign up button. * Minifying docker image. * Removing sortpack.
2023-10-31 13:31:03 +00:00
let language: string;
if (req.query["lang"] != null) {
language = req.query["lang"].toString();
res.cookie("lang", language, {
expires: new Date(Date.now() + 60 * 60 * 24 * 7),
});
} else if (cookieLang != null) {
language = cookieLang;
} else {
language = req.headers["accept-language"]
? req.headers["accept-language"].split(",")[0]
: "en";
}
New tailwind-based joinlemmy-site (#243) * Starting on new tailwind based joinlemmy-site. * Formatting fix. * Adding follow communities block. * Adding a few more blocks. * Finishing up blocks. * Adding a few more pages. * Adding apps page. * Almost done with donation page. * Adding most of instances page. * Trying to fix CI 1. * Adding navbar and footer. * Adding bottom spacer. * Finishing up more info modal. * Adding icons to main page. * Eruda only in development mode. * Finishing up main page, starting to work on recs. * Adding main images. * Adding images 2. * Starting to add filters. * Finishing up helper modal. * Adding topic icons. * Adding more instances. * Fixing recommended. * Forgot to add instance picker. * Adding world background image. * Adding alexandrite. * Adding funding goal block. * Fix dockerfile. * Upgrading deps. * Fixing package json. * Updating coders, sponsors. * Fixing mobile margins. * Fixing navbar auto-close when clicked. * Removing todo. * Removing some useless instance helper links. * Fixing news titling. * Addressing PR comments. * Updating instance stats. * Fixing class -> className * Fixing sm:max directives. * Make instance images links to their sites. * Use ubuntu font. * Addressing PR comments. * Adding a few more android apps. * Adding thunder and combustible apps. * Fixing z index. * Add a warning alert for closed source apps. * Adding MLMYM app. Fixes #213 * Fixing i18n key. * Adding QR codes for cryptos. Fixes #219 * Addressing PR comments. * Fixing news preview. * Adding registration mode to details modal. Fixes #153 * Filter out bot instances. * Using glide carousel. * Adding glide min css. * Adding donation platform fetching. Fixes #248 * Prettying glide css. * Change dev goal to 3 * Adding sign up button. * Minifying docker image. * Removing sortpack.
2023-10-31 13:31:03 +00:00
return language;
}
server.get("/*", async (req, res) => {
// const activeRoute = routes.find(route => matchPath(req.path, route)) || {};
const context = {} as any;
const language = setLanguage(req, res);
i18n.changeLanguage(language);
const wrapper = (
<StaticRouter location={req.url} context={context}>
<App />
</StaticRouter>
);
if (context.url) {
return res.redirect(context.url);
}
const root = renderToString(wrapper);
const helmet = Helmet.renderStatic();
res.send(`
<!DOCTYPE html>
New tailwind-based joinlemmy-site (#243) * Starting on new tailwind based joinlemmy-site. * Formatting fix. * Adding follow communities block. * Adding a few more blocks. * Finishing up blocks. * Adding a few more pages. * Adding apps page. * Almost done with donation page. * Adding most of instances page. * Trying to fix CI 1. * Adding navbar and footer. * Adding bottom spacer. * Finishing up more info modal. * Adding icons to main page. * Eruda only in development mode. * Finishing up main page, starting to work on recs. * Adding main images. * Adding images 2. * Starting to add filters. * Finishing up helper modal. * Adding topic icons. * Adding more instances. * Fixing recommended. * Forgot to add instance picker. * Adding world background image. * Adding alexandrite. * Adding funding goal block. * Fix dockerfile. * Upgrading deps. * Fixing package json. * Updating coders, sponsors. * Fixing mobile margins. * Fixing navbar auto-close when clicked. * Removing todo. * Removing some useless instance helper links. * Fixing news titling. * Addressing PR comments. * Updating instance stats. * Fixing class -> className * Fixing sm:max directives. * Make instance images links to their sites. * Use ubuntu font. * Addressing PR comments. * Adding a few more android apps. * Adding thunder and combustible apps. * Fixing z index. * Add a warning alert for closed source apps. * Adding MLMYM app. Fixes #213 * Fixing i18n key. * Adding QR codes for cryptos. Fixes #219 * Addressing PR comments. * Fixing news preview. * Adding registration mode to details modal. Fixes #153 * Filter out bot instances. * Using glide carousel. * Adding glide min css. * Adding donation platform fetching. Fixes #248 * Prettying glide css. * Change dev goal to 3 * Adding sign up button. * Minifying docker image. * Removing sortpack.
2023-10-31 13:31:03 +00:00
<html ${helmet.htmlAttributes.toString()} lang="en" class="scroll-smooth">
<head>
New tailwind-based joinlemmy-site (#243) * Starting on new tailwind based joinlemmy-site. * Formatting fix. * Adding follow communities block. * Adding a few more blocks. * Finishing up blocks. * Adding a few more pages. * Adding apps page. * Almost done with donation page. * Adding most of instances page. * Trying to fix CI 1. * Adding navbar and footer. * Adding bottom spacer. * Finishing up more info modal. * Adding icons to main page. * Eruda only in development mode. * Finishing up main page, starting to work on recs. * Adding main images. * Adding images 2. * Starting to add filters. * Finishing up helper modal. * Adding topic icons. * Adding more instances. * Fixing recommended. * Forgot to add instance picker. * Adding world background image. * Adding alexandrite. * Adding funding goal block. * Fix dockerfile. * Upgrading deps. * Fixing package json. * Updating coders, sponsors. * Fixing mobile margins. * Fixing navbar auto-close when clicked. * Removing todo. * Removing some useless instance helper links. * Fixing news titling. * Addressing PR comments. * Updating instance stats. * Fixing class -> className * Fixing sm:max directives. * Make instance images links to their sites. * Use ubuntu font. * Addressing PR comments. * Adding a few more android apps. * Adding thunder and combustible apps. * Fixing z index. * Add a warning alert for closed source apps. * Adding MLMYM app. Fixes #213 * Fixing i18n key. * Adding QR codes for cryptos. Fixes #219 * Addressing PR comments. * Fixing news preview. * Adding registration mode to details modal. Fixes #153 * Filter out bot instances. * Using glide carousel. * Adding glide min css. * Adding donation platform fetching. Fixes #248 * Prettying glide css. * Change dev goal to 3 * Adding sign up button. * Minifying docker image. * Removing sortpack.
2023-10-31 13:31:03 +00:00
${erudaInit()}
${helmet.title.toString()}
${helmet.meta.toString()}
<!-- Required meta tags -->
<meta name="Description" content="Lemmy">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Icons -->
<link rel="shortcut icon" type="image/svg+xml" href="/static/assets/icons/favicon.svg" />
<link rel="apple-touch-icon" href="/static/assets/icons/apple-touch-icon.png" />
<!-- Styles -->
<link rel="stylesheet" type="text/css" href="/static/styles/styles.css" />
New tailwind-based joinlemmy-site (#243) * Starting on new tailwind based joinlemmy-site. * Formatting fix. * Adding follow communities block. * Adding a few more blocks. * Finishing up blocks. * Adding a few more pages. * Adding apps page. * Almost done with donation page. * Adding most of instances page. * Trying to fix CI 1. * Adding navbar and footer. * Adding bottom spacer. * Finishing up more info modal. * Adding icons to main page. * Eruda only in development mode. * Finishing up main page, starting to work on recs. * Adding main images. * Adding images 2. * Starting to add filters. * Finishing up helper modal. * Adding topic icons. * Adding more instances. * Fixing recommended. * Forgot to add instance picker. * Adding world background image. * Adding alexandrite. * Adding funding goal block. * Fix dockerfile. * Upgrading deps. * Fixing package json. * Updating coders, sponsors. * Fixing mobile margins. * Fixing navbar auto-close when clicked. * Removing todo. * Removing some useless instance helper links. * Fixing news titling. * Addressing PR comments. * Updating instance stats. * Fixing class -> className * Fixing sm:max directives. * Make instance images links to their sites. * Use ubuntu font. * Addressing PR comments. * Adding a few more android apps. * Adding thunder and combustible apps. * Fixing z index. * Add a warning alert for closed source apps. * Adding MLMYM app. Fixes #213 * Fixing i18n key. * Adding QR codes for cryptos. Fixes #219 * Addressing PR comments. * Fixing news preview. * Adding registration mode to details modal. Fixes #153 * Filter out bot instances. * Using glide carousel. * Adding glide min css. * Adding donation platform fetching. Fixes #248 * Prettying glide css. * Change dev goal to 3 * Adding sign up button. * Minifying docker image. * Removing sortpack.
2023-10-31 13:31:03 +00:00
<link rel="stylesheet" href="/static/assets/glide.core.min.css">
${helmet.link.toString()}
</head>
<body ${helmet.bodyAttributes.toString()}>
<div id='root'>${root}</div>
<script defer src='/static/js/client.js'></script>
2022-02-24 16:46:14 +00:00
<script defer data-domain="join-lemmy.org" src="https://plausible.join-lemmy.org/js/plausible.outbound-links.js"></script>
</body>
</html>
`);
});
server.listen(port, () => {
console.log(`http://localhost:${port}`);
});
process.on("SIGINT", () => {
console.info("Interrupted");
process.exit(0);
});