feat: wip previews for non-get routes
This commit is contained in:
parent
ee0b9e597a
commit
a23aee5d21
5 changed files with 366 additions and 24 deletions
55
index.js
55
index.js
|
|
@ -464,6 +464,11 @@ app.post("/workshop/:structure_id/route", (req, res) => {
|
|||
app.put("/workshop/:structure_id/route/:route_id", (req, res) => {
|
||||
const route = model.getRoute(db, req.params.route_id);
|
||||
model.updateRoute(db, { ...route, ...req.body });
|
||||
if (req.body.scaffold_page) {
|
||||
// TODO: make this send over scaffold page id too someday
|
||||
const latestPage = model.getLatestScaffoldPage(db, req.params.route_id)
|
||||
model.updateScaffoldPage(db, { ...latestPage, content: req.body.scaffold_page })
|
||||
}
|
||||
if (route.verb == "WS") {
|
||||
bootstrapWebsocketHandler({ ...route, ...req.body })
|
||||
}
|
||||
|
|
@ -575,11 +580,6 @@ app.put("/workshop/:structure_id/template/:template_id", (req, res) => {
|
|||
app.get("/workshop/:structure_id/template/:template_id", (req, res) => {
|
||||
const template = model.getTemplate(db, req.params.template_id);
|
||||
|
||||
console.log("wassup", {
|
||||
template: template,
|
||||
...sidebarStuff(db, req.params.structure_id),
|
||||
});
|
||||
|
||||
return res.send(
|
||||
bootstrapTemplateWithHTMXetc(
|
||||
eta.render("workshop/template", {
|
||||
|
|
@ -594,7 +594,6 @@ app.get("/workshop/:structure_id/template/:template_id/preview", (req, res) => {
|
|||
const template = model.getTemplate(db, req.params.template_id);
|
||||
const struct = model.getStructure(db, req.params.structure_id);
|
||||
const eta = model.getTemplater(req.params.structure_id);
|
||||
console.log(template);
|
||||
|
||||
const context = vm.createContext({ it: null });
|
||||
vm.runInContext(template.test_object, context);
|
||||
|
|
@ -621,22 +620,54 @@ app.get("/workshop/:structure_id/route/:id", (req, res) => {
|
|||
db,
|
||||
req.params.structure_id,
|
||||
).route_prefix;
|
||||
let previewUrl = routePrefix
|
||||
? path.join(routePrefix || "", route.path)
|
||||
: route.path;
|
||||
let previewUrl = null;
|
||||
|
||||
if (route["verb"] == "GET" ) {
|
||||
previewUrl = routePrefix
|
||||
? path.join(routePrefix || "", route.path)
|
||||
: route.path;
|
||||
}
|
||||
else {
|
||||
previewUrl = `/workshop/${req.params.structure_id}/route/${req.params.id}/preview`;
|
||||
}
|
||||
|
||||
template = route["verb"] == "GET" ? "workshop/route" : "workshop/cud_route";
|
||||
|
||||
return res.send(
|
||||
bootstrapTemplateWithHTMXetc(
|
||||
eta.render("workshop/route", {
|
||||
eta.render(template, {
|
||||
route: route,
|
||||
previewUrl:
|
||||
route["verb"] == "GET" ? previewUrl : "/workshop/do-something-here",
|
||||
previewUrl: previewUrl,
|
||||
...sidebarStuff(db, req.params.structure_id),
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
app.get("/workshop/:structure_id/route/:route_id/preview", (req, res) => {
|
||||
const route = model.getRoute(db, req.params.route_id);
|
||||
const struct = model.getStructure(db, req.params.structure_id);
|
||||
|
||||
const it = {
|
||||
route: function (url) {
|
||||
return struct.route_prefix ? path.join(struct.route_prefix, url) : url;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(route)
|
||||
|
||||
return res.send(
|
||||
bootstrapTemplateWithHTMXetc(
|
||||
eta.renderString(route.scaffold_page_content, it),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
struct.head_injection,
|
||||
false,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
app.get("/workshop/:structure_id/route/:route_id/logs", (req, res) => {
|
||||
const since = req.query.since;
|
||||
let logs = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue