forked from cms/tibi-svelte-starter
fixed ssr
This commit is contained in:
parent
71fd86b376
commit
46c8119548
@ -7,7 +7,7 @@ var utils = require("../lib/utils")
|
|||||||
var url = request.query("url")
|
var url = request.query("url")
|
||||||
var noCache = request.query("noCache")
|
var noCache = request.query("noCache")
|
||||||
|
|
||||||
var trace_id = context.sentryTraceId()
|
var trace_id = context.debug.sentryTraceId()
|
||||||
function addSentryTrace(content) {
|
function addSentryTrace(content) {
|
||||||
return content.replace(
|
return content.replace(
|
||||||
"</head>",
|
"</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) {
|
if (url) {
|
||||||
var comment = ""
|
var comment = ""
|
||||||
@ -32,7 +32,7 @@ var utils = require("../lib/utils")
|
|||||||
|
|
||||||
var cache =
|
var cache =
|
||||||
!noCache &&
|
!noCache &&
|
||||||
context.readCollection("ssr", {
|
context.db.find("ssr", {
|
||||||
filter: {
|
filter: {
|
||||||
path: url,
|
path: url,
|
||||||
},
|
},
|
||||||
@ -96,7 +96,7 @@ var utils = require("../lib/utils")
|
|||||||
endpoint,
|
endpoint,
|
||||||
JSON.stringify(_options)
|
JSON.stringify(_options)
|
||||||
)*/
|
)*/
|
||||||
var goSlice = context.readCollection(
|
var goSlice = context.db.find(
|
||||||
endpoint,
|
endpoint,
|
||||||
_options || {}
|
_options || {}
|
||||||
)
|
)
|
||||||
@ -114,10 +114,7 @@ var utils = require("../lib/utils")
|
|||||||
var count = (data && data.length) || 0
|
var count = (data && data.length) || 0
|
||||||
if (options && count == options.limit) {
|
if (options && count == options.limit) {
|
||||||
// read count from db
|
// read count from db
|
||||||
count = context.readCollectionCount(
|
count = context.db.count(endpoint, _options || {})
|
||||||
endpoint,
|
|
||||||
_options || {}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
var r = { data: data, count: count }
|
var r = { data: data, count: count }
|
||||||
|
|
||||||
@ -147,15 +144,13 @@ var utils = require("../lib/utils")
|
|||||||
|
|
||||||
cacheIt = true
|
cacheIt = true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
utils.log(e)
|
utils.log(e.message)
|
||||||
for (var property in e) {
|
utils.log(e.stack)
|
||||||
utils.log(property + ": " + e[property])
|
error = "error: " + e.message + "\n\n" + e.stack
|
||||||
}
|
|
||||||
error = JSON.stringify(e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tpl = context.file("templates/spa.html")
|
var tpl = context.fs.readFile("templates/spa.html")
|
||||||
tpl = tpl.replace("<!--HEAD-->", head)
|
tpl = tpl.replace("<!--HEAD-->", head)
|
||||||
tpl = tpl.replace("<!--HTML-->", html)
|
tpl = tpl.replace("<!--HTML-->", html)
|
||||||
tpl = tpl.replace(
|
tpl = tpl.replace(
|
||||||
@ -169,7 +164,7 @@ var utils = require("../lib/utils")
|
|||||||
|
|
||||||
if (cacheIt && !noCache) {
|
if (cacheIt && !noCache) {
|
||||||
// save cache
|
// save cache
|
||||||
context.createDocument("ssr", {
|
context.db.create("ssr", {
|
||||||
path: url,
|
path: url,
|
||||||
content: tpl,
|
content: tpl,
|
||||||
})
|
})
|
||||||
@ -185,7 +180,7 @@ var utils = require("../lib/utils")
|
|||||||
html: addSentryTrace(tpl),
|
html: addSentryTrace(tpl),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var auth = context.auth()
|
var auth = context.user.auth()
|
||||||
if (!auth || auth.role !== 0) {
|
if (!auth || auth.role !== 0) {
|
||||||
// only admins are allowed
|
// only admins are allowed
|
||||||
throw {
|
throw {
|
||||||
|
Loading…
Reference in New Issue
Block a user