diff --git a/client/admin/main.jsx b/client/admin/main.jsx
index e69de29bb..bd380789a 100644
--- a/client/admin/main.jsx
+++ b/client/admin/main.jsx
@@ -0,0 +1,6 @@
+import { createRoot } from "react-dom/client";
+import Admin from "./admin.jsx";
+
+const props = window.__INITIAL_PROPS__ || {};
+
+createRoot(document.getElementById("reactRoot")).render();
diff --git a/client/template.js b/client/template.js
deleted file mode 100644
index 62f13bf88..000000000
--- a/client/template.js
+++ /dev/null
@@ -1,66 +0,0 @@
-import fs from "fs";
-
-const isProd = process.env.NODE_ENV === "production";
-
-const template = async function ({ vite, url }, name, title = "", props = {}) {
- const ogTags = [];
- const ogMeta = props.ogMeta ?? {};
-
- Object.entries(ogMeta).forEach(([key, value]) => {
- if (!value) return;
- ogTags.push(``);
- });
-
- const ogMetaTags = ogTags.join("\n");
-
- // ----------------
- // PROD
- // ----------------
- if (isProd) {
- const ssrModule = await import(`../build/entry-server-${name}/bundle.js`);
-
- return `
-
-
-
-
-
-
- ${ogMetaTags}
-
- ${title.length ? `${title} - The Homebrewery` : "The Homebrewery - NaturalCrit"}
-
-
- ${ssrModule.default(props)}
-
-
-
-`;
- }
-
- // ----------------
- // DEV
- // ----------------
- const { default: render } = await vite.ssrLoadModule(`/client/entry-server-${name}.jsx`);
-
- let html = `
-
-
-
- ${ogMetaTags}
- ${title.length ? `${title} - The Homebrewery` : "The Homebrewery - NaturalCrit"}
-
-
- ${render(props)}
-
-
-
-
-
-
-`;
-
- return vite.transformIndexHtml(url, html);
-};
-
-export default template;
diff --git a/index.html b/index.html
index 5870aef2c..5ee864b28 100644
--- a/index.html
+++ b/index.html
@@ -1,23 +1,29 @@
-
-
-
-
-
+
+
+
+
+
-
- The Homebrewery - NaturalCrit
-
+
+ The Homebrewery - NaturalCrit
+
-
-
+
+
-
-
+
+
diff --git a/server.js b/server.js
index 172da0fe2..cd44c68cb 100644
--- a/server.js
+++ b/server.js
@@ -13,7 +13,6 @@ async function start() {
server: { middlewareMode: true },
appType: "custom",
});
-
}
await DB.connect(config).catch((err) => {
diff --git a/server/admin.api.js b/server/admin.api.js
index a3d7622f1..93e0036d1 100644
--- a/server/admin.api.js
+++ b/server/admin.api.js
@@ -4,18 +4,23 @@ import { model as NotificationModel } from './notifications.model.js';
import express from 'express';
import Moment from 'moment';
import zlib from 'zlib';
-import templateFn from '../client/template.js';
+import config from './config.js';
+import path from 'path';
+import fs from 'fs-extra';
+
+const nodeEnv = config.get('node_env');
+const isProd = nodeEnv === 'production';
import HomebrewAPI from './homebrew.api.js';
import asyncHandler from 'express-async-handler';
import { splitTextStyleAndMetadata } from '../shared/helpers.js';
-const router = express.Router();
-
-
process.env.ADMIN_USER = process.env.ADMIN_USER || 'admin';
process.env.ADMIN_PASS = process.env.ADMIN_PASS || 'password3';
+export default function createAdminApi(vite) {
+ const router = express.Router();
+
const mw = {
adminOnly : (req, res, next)=>{
if(!req.get('authorization')){
@@ -371,15 +376,28 @@ router.delete('/admin/notification/delete/:id', mw.adminOnly, async (req, res, n
}
});
-router.get('/admin', mw.adminOnly, (req, res)=>{
- templateFn('admin', {
+router.get('/admin', mw.adminOnly, asyncHandler(async (req, res) => {
+ const props = {
url : req.originalUrl
- })
- .then((page)=>res.send(page))
- .catch((err)=>{
- console.log(err);
- res.sendStatus(500);
- });
-});
+ };
+
+ const htmlPath = isProd
+ ? path.resolve('build', 'index.html')
+ : path.resolve('index.html');
+
+ let html = fs.readFileSync(htmlPath, 'utf-8');
+
+ if (!isProd && vite?.transformIndexHtml) {
+ html = await vite.transformIndexHtml(req.originalUrl, html);
+ }
+
+ res.send(html.replace(
+ '',
+ `\n`
+ ));
+}));
+
+
+ return router;
+}
-export default router;
diff --git a/server/app.js b/server/app.js
index 1cb5f4169..07fc3ba9c 100644
--- a/server/app.js
+++ b/server/app.js
@@ -44,7 +44,6 @@ export default async function createApp(vite) {
const isProd = nodeEnv === 'production';
const isLocalEnvironment = config.get('local_environments').includes(nodeEnv);
-
const sanitizeBrew = (brew, accessType)=>{
brew._id = undefined;
brew.__v = undefined;
@@ -114,7 +113,7 @@ export default async function createApp(vite) {
});
app.use(homebrewApi);
- app.use(adminApi);
+ app.use(adminApi(vite));
app.use(vaultApi);
const welcomeText = fs.readFileSync('./client/homebrew/pages/homePage/welcome_msg.md', 'utf8');