diff --git a/web/ASC.Web.Editor/src/index.js b/web/ASC.Web.Editor/src/index.js index 50599f7ad8..960fdad0c1 100644 --- a/web/ASC.Web.Editor/src/index.js +++ b/web/ASC.Web.Editor/src/index.js @@ -1 +1,23 @@ -import("./bootstrap"); +import express from "express"; +import path from "path"; +import template from "./src/server/template"; +import render from "./src/server/render"; + +const app = express(); + +app.use( + "/products/files/doceditor/static/scripts/", + express.static(path.resolve(__dirname, "static/scripts")) +); +app.use("/media", express.static(path.resolve(__dirname, "media"))); + +app.disable("x-powered-by"); + +app.listen(process.env.PORT || 5013); + +app.get("/products/files/doceditor/", async (req, res) => { + const { props, content } = await render(req); + const response = template("Server Rendered Page", props, content); + res.setHeader("Cache-Control", "assets, max-age=604800"); + res.send(response); +}); diff --git a/web/ASC.Web.Editor/src/server/render.js b/web/ASC.Web.Editor/src/server/render.js new file mode 100644 index 0000000000..8b45fd1b2a --- /dev/null +++ b/web/ASC.Web.Editor/src/server/render.js @@ -0,0 +1,14 @@ +import React from "react"; +import { renderToString } from "react-dom/server"; +import App from "../Editor.js"; +import { initDocEditor } from "./helpers/utils"; + +export default async (req) => { + const props = await initDocEditor(req); + + let content = renderToString(); + + // Get a copy of store data to create the same store on client side + + return { app, content }; +}; diff --git a/web/ASC.Web.Editor/src/server/template.js b/web/ASC.Web.Editor/src/server/template.js new file mode 100644 index 0000000000..07a3c6084e --- /dev/null +++ b/web/ASC.Web.Editor/src/server/template.js @@ -0,0 +1,26 @@ +export default function template(title, initialState = {}, content = "") { + let scripts = ""; // Dynamically ship scripts based on render type + if (content) { + scripts = ` + + `; + } else { + scripts = ` `; + } + let page = ` + + + + ${title} + + + +
${content}
+ ${scripts} + + `; + + return page; +}