fixed ssr

This commit is contained in:
Sebastian Frank 2022-01-19 18:50:58 +01:00
parent 71fd86b376
commit 46c8119548
Signed by: apairon
GPG Key ID: A0E05A8199CE3F57

View File

@ -7,7 +7,7 @@ var utils = require("../lib/utils")
var url = request.query("url")
var noCache = request.query("noCache")
var trace_id = context.sentryTraceId()
var trace_id = context.debug.sentryTraceId()
function addSentryTrace(content) {
return content.replace(
"</head>",
@ -15,7 +15,7 @@ var utils = require("../lib/utils")
)
}
context.header("sentry-trace", trace_id)
context.response.header("sentry-trace", trace_id)
if (url) {
var comment = ""
@ -32,7 +32,7 @@ var utils = require("../lib/utils")
var cache =
!noCache &&
context.readCollection("ssr", {
context.db.find("ssr", {
filter: {
path: url,
},
@ -96,7 +96,7 @@ var utils = require("../lib/utils")
endpoint,
JSON.stringify(_options)
)*/
var goSlice = context.readCollection(
var goSlice = context.db.find(
endpoint,
_options || {}
)
@ -114,10 +114,7 @@ var utils = require("../lib/utils")
var count = (data && data.length) || 0
if (options && count == options.limit) {
// read count from db
count = context.readCollectionCount(
endpoint,
_options || {}
)
count = context.db.count(endpoint, _options || {})
}
var r = { data: data, count: count }
@ -147,15 +144,13 @@ var utils = require("../lib/utils")
cacheIt = true
} catch (e) {
utils.log(e)
for (var property in e) {
utils.log(property + ": " + e[property])
}
error = JSON.stringify(e)
utils.log(e.message)
utils.log(e.stack)
error = "error: " + e.message + "\n\n" + e.stack
}
}
var tpl = context.file("templates/spa.html")
var tpl = context.fs.readFile("templates/spa.html")
tpl = tpl.replace("<!--HEAD-->", head)
tpl = tpl.replace("<!--HTML-->", html)
tpl = tpl.replace(
@ -169,7 +164,7 @@ var utils = require("../lib/utils")
if (cacheIt && !noCache) {
// save cache
context.createDocument("ssr", {
context.db.create("ssr", {
path: url,
content: tpl,
})
@ -185,7 +180,7 @@ var utils = require("../lib/utils")
html: addSentryTrace(tpl),
}
} else {
var auth = context.auth()
var auth = context.user.auth()
if (!auth || auth.role !== 0) {
// only admins are allowed
throw {