yarn package upgrades, ssr update
This commit is contained in:
parent
f1d30945c1
commit
942f92c477
17
Makefile
17
Makefile
@ -1,9 +1,8 @@
|
|||||||
DOCKER_COMPOSE=docker compose -f docker-compose-local.yml
|
DOCKER_COMPOSE=docker compose -f docker-compose-local.yml
|
||||||
DOCKER_ALL_PROFILES=--profile docpress --profile tibi-dev --profile tibi --profile chisel
|
|
||||||
|
|
||||||
.DEFAULT_GOAL := help
|
.DEFAULT_GOAL := help
|
||||||
|
|
||||||
.PHONY: docker-up docker-up-tibi-dev docker-up-chisel docker-up-docpress docker-start docker-start-tibi-dev docker-down docker-ps docker-logs docker-pull yarn-upgrade fix-permissions
|
.PHONY: docker-up docker-up-tibi-dev docker-start docker-start-tibi-dev docker-down docker-ps docker-logs yarn-upgrade fix-permissions
|
||||||
|
|
||||||
include ./.env
|
include ./.env
|
||||||
|
|
||||||
@ -21,25 +20,25 @@ docker-up-chisel: ## bring up chisel tunnel
|
|||||||
$(DOCKER_COMPOSE) --profile chisel up -d
|
$(DOCKER_COMPOSE) --profile chisel up -d
|
||||||
|
|
||||||
docker-down: ## take docker compose stack down
|
docker-down: ## take docker compose stack down
|
||||||
$(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) down
|
$(DOCKER_COMPOSE) --profile tibi-dev --profile tibi --profile chisel down
|
||||||
|
|
||||||
docker-start: ## start docker compose stack in foreground and take it down after CTRL-C
|
docker-start: ## start docker compose stack in foreground and take it down after CTRL-C
|
||||||
$(DOCKER_COMPOSE) --profile tibi up; $(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) down
|
$(DOCKER_COMPOSE) --profile tibi up; $(DOCKER_COMPOSE) --profile tibi-dev --profile tibi --profile chisel down
|
||||||
|
|
||||||
docker-start-tibi-dev: ## start docker compose stack in foreground and take it down after CTRL-C (with tibi-dev)
|
docker-start-tibi-dev: ## start docker compose stack in foreground and take it down after CTRL-C (with tibi-dev)
|
||||||
$(DOCKER_COMPOSE) --profile tibi-dev up; $(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) down
|
$(DOCKER_COMPOSE) --profile tibi-dev up; $(DOCKER_COMPOSE) --profile tibi-dev --profile tibi --profile chisel down
|
||||||
|
|
||||||
docker-ps: ## show container state
|
docker-ps: ## show container state
|
||||||
$(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) ps
|
$(DOCKER_COMPOSE) --profile tibi-dev --profile tibi --profile chisel ps
|
||||||
|
|
||||||
docker-logs: ## show docker logs and follow
|
docker-logs: ## show docker logs and follow
|
||||||
$(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) logs -f || true
|
$(DOCKER_COMPOSE) --profile tibi-dev --profile tibi --profile chisel logs -f --tail=100 || true
|
||||||
|
|
||||||
docker-pull: ## pull docker images
|
docker-pull: ## pull docker images
|
||||||
$(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) pull
|
$(DOCKER_COMPOSE) --profile tibi-dev --profile tibi --profile chisel pull
|
||||||
|
|
||||||
docker-%:
|
docker-%:
|
||||||
$(DOCKER_COMPOSE) $(DOCKER_ALL_PROFILES) $*
|
$(DOCKER_COMPOSE) $*
|
||||||
|
|
||||||
yarn-upgrade: # interactive yarn upgrade
|
yarn-upgrade: # interactive yarn upgrade
|
||||||
$(DOCKER_COMPOSE) run --rm yarnstart yarn upgrade-interactive
|
$(DOCKER_COMPOSE) run --rm yarnstart yarn upgrade-interactive
|
||||||
|
@ -17,9 +17,6 @@ meta:
|
|||||||
# Die Bildgröße für die Einbindung ins erzeugte HTML des ContentBuilder
|
# Die Bildgröße für die Einbindung ins erzeugte HTML des ContentBuilder
|
||||||
# hat hiermit nix zu tun.
|
# hat hiermit nix zu tun.
|
||||||
defaultImageFilter: s
|
defaultImageFilter: s
|
||||||
multiupload:
|
|
||||||
fields:
|
|
||||||
- source: description
|
|
||||||
|
|
||||||
multiupload:
|
multiupload:
|
||||||
fields:
|
fields:
|
||||||
@ -32,7 +29,6 @@ meta:
|
|||||||
return "Title" + $file.name
|
return "Title" + $file.name
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
|
||||||
# Wird unter "image-/file-/videoSelect" im ContentBuilder Feld kein
|
# Wird unter "image-/file-/videoSelect" im ContentBuilder Feld kein
|
||||||
# "subNavigation" Index definiert, werden auch folgende "views"
|
# "subNavigation" Index definiert, werden auch folgende "views"
|
||||||
# verwendet.
|
# verwendet.
|
||||||
@ -47,7 +43,7 @@ meta:
|
|||||||
secondaryText:
|
secondaryText:
|
||||||
source: title
|
source: title
|
||||||
filter: true
|
filter: true
|
||||||
|
|
||||||
tertiaryText:
|
tertiaryText:
|
||||||
source: description
|
source: description
|
||||||
filter: true
|
filter: true
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const release = "tibi-docs.dirty"
|
const release = "tibi-docs.dirty"
|
||||||
|
const apiClientBaseURL = "/api/"
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (release && typeof context !== "undefined") {
|
if (release && typeof context !== "undefined") {
|
||||||
@ -7,4 +8,5 @@ if (release && typeof context !== "undefined") {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
release,
|
release,
|
||||||
|
apiClientBaseURL,
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,35 @@
|
|||||||
|
const publishedFilter = {
|
||||||
|
$or: [
|
||||||
|
{ publishDate: { $exists: false } },
|
||||||
|
{ publishDate: null },
|
||||||
|
{
|
||||||
|
publishDate: { $lte: { $date: new Date().toISOString() } },
|
||||||
|
// publishDate: { $lte: new Date() },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiSsrBaseURL = "http://localhost:8080/api/v1/_/demo/"
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ssrValidatePath: function (path) {
|
publishedFilter,
|
||||||
|
apiSsrBaseURL,
|
||||||
|
ssrValidatePath: function (/** @type {string} */ path) {
|
||||||
// validate if path ssr rendering is ok, -1 = NOTFOUND, 0 = NO SSR, 1 = SSR
|
// validate if path ssr rendering is ok, -1 = NOTFOUND, 0 = NO SSR, 1 = SSR
|
||||||
// pe. use context.readCollection("product", {filter: {path: path}}) ... to validate dynamic urls
|
// pe. use context.readCollection("product", {filter: {path: path}}) ... to validate dynamic urls
|
||||||
|
|
||||||
// / is de home
|
// // / is de home
|
||||||
if (path == "/") return 1
|
// if (path == "/") return 1
|
||||||
|
|
||||||
// all other sites are in db
|
// // all other sites are in db
|
||||||
path = path?.replace(/^\//, "")
|
// path = path?.replace(/^\//, "")
|
||||||
|
|
||||||
// filter for path or alternativePaths
|
// filter for path or alternativePaths
|
||||||
const resp = context.db.find("content", {
|
const resp = context.db.find("content", {
|
||||||
filter: {
|
filter: {
|
||||||
$or: [{ path }, { "alternativePaths.path": path }],
|
$and: [{ $or: [{ path }, { "alternativePaths.path": path }] }, publishedFilter],
|
||||||
},
|
},
|
||||||
|
|
||||||
selector: { _id: 1 },
|
selector: { _id: 1 },
|
||||||
})
|
})
|
||||||
if (resp && resp.length) {
|
if (resp && resp.length) {
|
||||||
@ -23,5 +39,5 @@ module.exports = {
|
|||||||
// not found
|
// not found
|
||||||
return -1
|
return -1
|
||||||
},
|
},
|
||||||
ssrAllowedAPIEndpoints: ["content", "medialib"],
|
ssrPublishCheckCollections: ["content"],
|
||||||
}
|
}
|
||||||
|
65
api/hooks/lib/ssr-server.js
Normal file
65
api/hooks/lib/ssr-server.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
const { apiSsrBaseURL, ssrPublishCheckCollections } = require("../config")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api request via server, cache result in context.ssrCache
|
||||||
|
* should be elimated in client code via tree shaking
|
||||||
|
*
|
||||||
|
* @param {string} cacheKey
|
||||||
|
* @param {string} endpoint
|
||||||
|
* @param {string} query
|
||||||
|
* @param {ApiOptions} options
|
||||||
|
* @returns {ApiResult<any>}
|
||||||
|
*/
|
||||||
|
function ssrRequest(cacheKey, endpoint, query, options) {
|
||||||
|
let url = endpoint + (query ? "?" + query : "")
|
||||||
|
|
||||||
|
if (ssrPublishCheckCollections.includes(endpoint)) {
|
||||||
|
// @ts-ignore
|
||||||
|
let validUntil = context.ssrCacheValidUntil
|
||||||
|
|
||||||
|
// check in db for publish date to invalidate cache
|
||||||
|
const _optionsPublishSearch = Object.assign(
|
||||||
|
{},
|
||||||
|
{ filter: options?.filter },
|
||||||
|
{
|
||||||
|
selector: { publishDate: 1 },
|
||||||
|
// projection: null,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
const publishSearch = context.db.find(endpoint, _optionsPublishSearch)
|
||||||
|
publishSearch?.forEach((item) => {
|
||||||
|
const publishDate = item.publishDate ? new Date(item.publishDate.unixMilli()) : null
|
||||||
|
|
||||||
|
if (publishDate && publishDate > new Date()) {
|
||||||
|
// entry has a publish date in the future, set global validUntil
|
||||||
|
if (validUntil == null || validUntil > publishDate) {
|
||||||
|
validUntil = publishDate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// @ts-ignore
|
||||||
|
context.ssrCacheValidUntil = validUntil
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log("############ FETCHING ", apiSsrBaseURL + url)
|
||||||
|
|
||||||
|
const response = context.http.fetch(apiSsrBaseURL + url, {
|
||||||
|
method: options.method,
|
||||||
|
headers: options.headers,
|
||||||
|
})
|
||||||
|
|
||||||
|
const json = response.body.json()
|
||||||
|
const count = parseInt(response.headers["x-results-count"] || "0")
|
||||||
|
|
||||||
|
// json is go data structure and incompatible with js, so we need to convert it
|
||||||
|
const r = { data: JSON.parse(JSON.stringify(json)), count: count }
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
context.ssrCache[cacheKey] = r
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
ssrRequest,
|
||||||
|
}
|
169
api/hooks/lib/ssr.js
Normal file
169
api/hooks/lib/ssr.js
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
const { apiClientBaseURL } = require("../config-client")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert object to string
|
||||||
|
* @param {any} obj object
|
||||||
|
*/
|
||||||
|
function obj2str(obj) {
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
return JSON.stringify(
|
||||||
|
obj.map(function (idx) {
|
||||||
|
return obj2str(idx)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
} else if (typeof obj === "object" && obj !== null) {
|
||||||
|
var elements = Object.keys(obj)
|
||||||
|
.sort()
|
||||||
|
.map(function (key) {
|
||||||
|
var val = obj2str(obj[key])
|
||||||
|
if (val) {
|
||||||
|
return key + ":" + val
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
var elementsCleaned = []
|
||||||
|
for (var i = 0; i < elements.length; i++) {
|
||||||
|
if (elements[i]) elementsCleaned.push(elements[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return "{" + elementsCleaned.join("|") + "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj) return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch polyfill
|
||||||
|
// [MIT License](LICENSE.md) © [Jason Miller](https://jasonformat.com/)
|
||||||
|
const _f = function (url, options) {
|
||||||
|
if (typeof XMLHttpRequest === "undefined") {
|
||||||
|
return Promise.resolve(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
options = options || {}
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const request = new XMLHttpRequest()
|
||||||
|
const keys = []
|
||||||
|
const all = []
|
||||||
|
const headers = {}
|
||||||
|
|
||||||
|
const response = () => ({
|
||||||
|
ok: ((request.status / 100) | 0) == 2, // 200-299
|
||||||
|
statusText: request.statusText,
|
||||||
|
status: request.status,
|
||||||
|
url: request.responseURL,
|
||||||
|
text: () => Promise.resolve(request.responseText),
|
||||||
|
json: () => Promise.resolve(request.responseText).then(JSON.parse),
|
||||||
|
blob: () => Promise.resolve(new Blob([request.response])),
|
||||||
|
clone: response,
|
||||||
|
headers: {
|
||||||
|
// @ts-ignore
|
||||||
|
keys: () => keys,
|
||||||
|
// @ts-ignore
|
||||||
|
entries: () => all,
|
||||||
|
get: (n) => headers[n.toLowerCase()],
|
||||||
|
has: (n) => n.toLowerCase() in headers,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
request.open(options.method || "get", url, true)
|
||||||
|
|
||||||
|
request.onload = () => {
|
||||||
|
request
|
||||||
|
.getAllResponseHeaders()
|
||||||
|
// @ts-ignore
|
||||||
|
.replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, (m, key, value) => {
|
||||||
|
keys.push((key = key.toLowerCase()))
|
||||||
|
all.push([key, value])
|
||||||
|
headers[key] = headers[key] ? `${headers[key]},${value}` : value
|
||||||
|
})
|
||||||
|
resolve(response())
|
||||||
|
}
|
||||||
|
|
||||||
|
request.onerror = reject
|
||||||
|
|
||||||
|
request.withCredentials = options.credentials == "include"
|
||||||
|
|
||||||
|
for (const i in options.headers) {
|
||||||
|
request.setRequestHeader(i, options.headers[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
request.send(options.body || null)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const _fetch = typeof fetch === "undefined" ? (typeof window === "undefined" ? _f : window.fetch || _f) : fetch
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api request via client or server
|
||||||
|
* server function ssrRequest is called via context.ssrRequest, binded in ssr hook
|
||||||
|
*
|
||||||
|
* @param {string} endpoint
|
||||||
|
* @param {ApiOptions} options
|
||||||
|
* @returns {Promise<ApiResult>}
|
||||||
|
*/
|
||||||
|
function apiRequest(endpoint, options) {
|
||||||
|
// first check cache if on client
|
||||||
|
const cacheKey = obj2str({ endpoint: endpoint, options: options })
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
if (typeof window !== "undefined" && window.__SSR_CACHE__) {
|
||||||
|
// @ts-ignore
|
||||||
|
const cache = window.__SSR_CACHE__[cacheKey]
|
||||||
|
console.log("SSR:", cacheKey, cache)
|
||||||
|
if (cache) {
|
||||||
|
return Promise.resolve(cache)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let method = "GET"
|
||||||
|
|
||||||
|
let query = "&count=1"
|
||||||
|
if (options?.filter) query += "&filter=" + encodeURIComponent(JSON.stringify(options.filter))
|
||||||
|
if (options?.sort) query += "&sort=" + options.sort + "&sort=_id"
|
||||||
|
if (options?.limit) query += "&limit=" + options.limit
|
||||||
|
if (options?.offset) query += "&offset=" + options.offset
|
||||||
|
if (options?.projection) query += "&projection=" + options.projection
|
||||||
|
if (options?.lookup) query += "&lookup=" + options.lookup
|
||||||
|
|
||||||
|
if (options?.params) {
|
||||||
|
Object.keys(options.params).forEach((p) => {
|
||||||
|
query += "&" + p + "=" + encodeURIComponent(options.params[p])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options?.headers) headers = { ...headers, ...options.headers }
|
||||||
|
|
||||||
|
if (typeof window === "undefined") {
|
||||||
|
// server
|
||||||
|
|
||||||
|
// reference via context from get hook to tree shake in client
|
||||||
|
// @ts-ignore
|
||||||
|
const d = context.ssrRequest(cacheKey, endpoint, query, Object.assign({}, options, { method, headers }))
|
||||||
|
return d
|
||||||
|
} else {
|
||||||
|
// client
|
||||||
|
let url = endpoint + (query ? "?" + query : "")
|
||||||
|
console.log("fetch", apiClientBaseURL + url)
|
||||||
|
return _fetch(apiClientBaseURL + url, {
|
||||||
|
method,
|
||||||
|
mode: "cors",
|
||||||
|
headers,
|
||||||
|
}).then((response) => {
|
||||||
|
return response?.json().then((json) => {
|
||||||
|
if (response?.status < 200 || response?.status >= 400) {
|
||||||
|
return Promise.reject({ response, data: json })
|
||||||
|
}
|
||||||
|
return Promise.resolve({ data: json || null, count: response.headers?.get("x-results-count") || 0 })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
obj2str,
|
||||||
|
apiRequest,
|
||||||
|
}
|
@ -6,38 +6,6 @@ function log(str) {
|
|||||||
console.log(JSON.stringify(str, undefined, 4))
|
console.log(JSON.stringify(str, undefined, 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* convert object to string
|
|
||||||
* @param {any} obj object
|
|
||||||
*/
|
|
||||||
function obj2str(obj) {
|
|
||||||
if (Array.isArray(obj)) {
|
|
||||||
return JSON.stringify(
|
|
||||||
obj.map(function (idx) {
|
|
||||||
return obj2str(idx)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
} else if (typeof obj === "object" && obj !== null) {
|
|
||||||
var elements = Object.keys(obj)
|
|
||||||
.sort()
|
|
||||||
.map(function (key) {
|
|
||||||
var val = obj2str(obj[key])
|
|
||||||
if (val) {
|
|
||||||
return key + ":" + val
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
var elementsCleaned = []
|
|
||||||
for (var i = 0; i < elements.length; i++) {
|
|
||||||
if (elements[i]) elementsCleaned.push(elements[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return "{" + elementsCleaned.join("|") + "}"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj) return obj
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clear SSR cache
|
* clear SSR cache
|
||||||
*/
|
*/
|
||||||
@ -49,5 +17,4 @@ function clearSSRCache() {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
log,
|
log,
|
||||||
clearSSRCache,
|
clearSSRCache,
|
||||||
obj2str,
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
const { ssrValidatePath, ssrAllowedAPIEndpoints } = require("../config")
|
// TODO: add query string functionality to cache
|
||||||
|
|
||||||
|
const { ssrValidatePath } = require("../config")
|
||||||
|
const { log } = require("../lib/utils")
|
||||||
|
const { ssrRequest } = require("../lib/ssr-server")
|
||||||
|
|
||||||
const { obj2str, log } = require("../lib/utils")
|
|
||||||
;(function () {
|
;(function () {
|
||||||
/** @type {HookResponse} */
|
/** @type {HookResponse} */
|
||||||
var response = null
|
// @ts-ignore
|
||||||
|
let response = null
|
||||||
|
|
||||||
var request = context.request()
|
const request = context.request()
|
||||||
var url = request.query("url")
|
let url = request.query("url")
|
||||||
var noCache = request.query("noCache")
|
const noCache = request.query("noCache")
|
||||||
|
|
||||||
// add sentry trace id to head
|
// add sentry trace id to head
|
||||||
var trace_id = context.debug.sentryTraceId()
|
const trace_id = context.debug.sentryTraceId()
|
||||||
|
/**
|
||||||
|
* @param {string} content
|
||||||
|
*/
|
||||||
function addSentryTrace(content) {
|
function addSentryTrace(content) {
|
||||||
return content.replace("</head>", '<meta name="sentry-trace" content="' + trace_id + '" /></head>')
|
return content.replace("</head>", '<meta name="sentry-trace" content="' + trace_id + '" /></head>')
|
||||||
}
|
}
|
||||||
@ -18,7 +25,9 @@ const { obj2str, log } = require("../lib/utils")
|
|||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
// comment will be printed to html later
|
// comment will be printed to html later
|
||||||
var comment = ""
|
let comment = ""
|
||||||
|
/** @type {Date} */ // @ts-ignore
|
||||||
|
context.ssrCacheValidUntil = null
|
||||||
|
|
||||||
url = url.split("?")[0]
|
url = url.split("?")[0]
|
||||||
comment += "url: " + url
|
comment += "url: " + url
|
||||||
@ -31,7 +40,8 @@ const { obj2str, log } = require("../lib/utils")
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if url is in cache
|
// check if url is in cache
|
||||||
var cache =
|
/** @type {Ssr[]} */ // @ts-ignore
|
||||||
|
const cache =
|
||||||
!noCache &&
|
!noCache &&
|
||||||
context.db.find("ssr", {
|
context.db.find("ssr", {
|
||||||
filter: {
|
filter: {
|
||||||
@ -39,93 +49,70 @@ const { obj2str, log } = require("../lib/utils")
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (cache && cache.length) {
|
if (cache && cache.length) {
|
||||||
// use cache
|
const validUntil = cache[0].validUntil ? new Date(cache[0].validUntil.unixMilli()) : null
|
||||||
throw {
|
// context.debug.dump("cache validUntil", validUntil)
|
||||||
status: 200,
|
if (!validUntil || validUntil > new Date()) {
|
||||||
log: false,
|
// context.debug.dump("using cache")
|
||||||
html: addSentryTrace(cache[0].content),
|
// use cache
|
||||||
|
context.response.header("X-SSR-Cache", "true")
|
||||||
|
throw {
|
||||||
|
status: 200,
|
||||||
|
log: false,
|
||||||
|
html: addSentryTrace(cache[0].content),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// cache is invalid, delete it
|
||||||
|
context.response.header("X-SSR-Cache", "invalid")
|
||||||
|
// @ts-ignore
|
||||||
|
context.db.delete("ssr", cache[0].id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate url
|
// validate url
|
||||||
var status = 200
|
let status = 200
|
||||||
|
|
||||||
var pNorender = false
|
let pNorender = false
|
||||||
var pNotfound = false
|
let pNotfound = false
|
||||||
|
|
||||||
var pR = ssrValidatePath(url)
|
const pR = ssrValidatePath(url)
|
||||||
if (pR < 0) {
|
if (pR < 0) {
|
||||||
pNotfound = true
|
pNotfound = true
|
||||||
} else if (!pR) {
|
} else if (!pR) {
|
||||||
pNorender = true
|
pNorender = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var head = ""
|
let head = ""
|
||||||
var html = ""
|
let html = ""
|
||||||
var error = ""
|
let error = ""
|
||||||
|
|
||||||
comment += ", path: " + url
|
comment += ", path: " + url
|
||||||
|
|
||||||
var cacheIt = false
|
let cacheIt = false
|
||||||
if (pNorender) {
|
if (pNorender) {
|
||||||
html = "<!-- NO SSR RENDERING -->"
|
html = "<!-- NO SSR RENDERING -->"
|
||||||
} else if (pNotfound) {
|
} else if (pNotfound) {
|
||||||
status = 404
|
status = 404
|
||||||
html = "404 NOT FOUND"
|
html = "404 NOT FOUND"
|
||||||
} else {
|
} else {
|
||||||
|
// @ts-ignore
|
||||||
|
context.ssrCache = {}
|
||||||
|
// @ts-ignore
|
||||||
|
context.ssrRequest = ssrRequest
|
||||||
|
|
||||||
// try rendering, if error output plain html
|
// try rendering, if error output plain html
|
||||||
try {
|
try {
|
||||||
// @ts-ignore
|
|
||||||
context.ssrCache = {}
|
|
||||||
// @ts-ignore
|
|
||||||
context.ssrFetch = function (endpoint, options) {
|
|
||||||
var data
|
|
||||||
if (ssrAllowedAPIEndpoints.indexOf(endpoint) > -1) {
|
|
||||||
var _options = Object.assign({}, options)
|
|
||||||
|
|
||||||
if (_options.sort) _options.sort = [_options.sort]
|
|
||||||
|
|
||||||
try {
|
|
||||||
/*console.log(
|
|
||||||
"SSR",
|
|
||||||
endpoint,
|
|
||||||
JSON.stringify(_options)
|
|
||||||
)*/
|
|
||||||
var goSlice = context.db.find(endpoint, _options || {})
|
|
||||||
// need to deep copy, so shift and delete on pure js is possible
|
|
||||||
data = JSON.parse(JSON.stringify(goSlice))
|
|
||||||
} catch (e) {
|
|
||||||
console.log("ERROR", JSON.stringify(e))
|
|
||||||
data = []
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log("SSR forbidden", endpoint)
|
|
||||||
data = []
|
|
||||||
}
|
|
||||||
|
|
||||||
var count = (data && data.length) || 0
|
|
||||||
if (options && count == options.limit) {
|
|
||||||
// read count from db
|
|
||||||
count = context.db.count(endpoint, _options || {})
|
|
||||||
}
|
|
||||||
var r = { data: data, count: count }
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
context.ssrCache[obj2str({ endpoint: endpoint, options: options })] = r
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// include App.svelte and render it
|
// include App.svelte and render it
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
var app = require("../lib/app.server")
|
|
||||||
var rendered = app.default.render({
|
// console.log("####### RENDERING ", url)
|
||||||
|
const app = require("../lib/app.server")
|
||||||
|
const rendered = app.default.render({
|
||||||
url: url,
|
url: url,
|
||||||
})
|
})
|
||||||
head = rendered.head
|
head = rendered.head
|
||||||
html = rendered.html
|
html = rendered.html
|
||||||
|
|
||||||
// add ssrCache to head
|
// add ssrCache to head, cache is built in ssr.js/apiRequest
|
||||||
head +=
|
head +=
|
||||||
"\n\n" +
|
"\n\n" +
|
||||||
"<script>window.__SSR_CACHE__ = " +
|
"<script>window.__SSR_CACHE__ = " +
|
||||||
@ -136,11 +123,12 @@ const { obj2str, log } = require("../lib/utils")
|
|||||||
// status from webapp
|
// status from webapp
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (context.is404) {
|
if (context.is404) {
|
||||||
|
// console.log("########## 404")
|
||||||
status = 404
|
status = 404
|
||||||
} else {
|
} else {
|
||||||
cacheIt = true
|
cacheIt = true
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (/** @type {any} */ e) {
|
||||||
// save error for later insert into html
|
// save error for later insert into html
|
||||||
log(e.message)
|
log(e.message)
|
||||||
log(e.stack)
|
log(e.stack)
|
||||||
@ -149,7 +137,7 @@ const { obj2str, log } = require("../lib/utils")
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read html template and replace placeholders
|
// read html template and replace placeholders
|
||||||
var tpl = context.fs.readFile("templates/spa.html")
|
let 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("<!--SSR.ERROR-->", error ? "<!--" + error + "-->" : "")
|
tpl = tpl.replace("<!--SSR.ERROR-->", error ? "<!--" + error + "-->" : "")
|
||||||
@ -158,8 +146,11 @@ const { obj2str, log } = require("../lib/utils")
|
|||||||
// save cache if adviced
|
// save cache if adviced
|
||||||
if (cacheIt && !noCache) {
|
if (cacheIt && !noCache) {
|
||||||
context.db.create("ssr", {
|
context.db.create("ssr", {
|
||||||
|
// context.debug.dump("ssr", {
|
||||||
path: url,
|
path: url,
|
||||||
content: tpl,
|
content: tpl,
|
||||||
|
// @ts-ignore
|
||||||
|
validUntil: context.ssrCacheValidUntil,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +162,7 @@ const { obj2str, log } = require("../lib/utils")
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// only admins are allowed to get without url parameter
|
// only admins are allowed to get without url parameter
|
||||||
var auth = context.user.auth()
|
const auth = context.user.auth()
|
||||||
if (!auth || auth.role !== 0) {
|
if (!auth || auth.role !== 0) {
|
||||||
throw {
|
throw {
|
||||||
status: 403,
|
status: 403,
|
||||||
|
@ -5,11 +5,13 @@ services:
|
|||||||
docpress:
|
docpress:
|
||||||
profiles:
|
profiles:
|
||||||
- docpress
|
- docpress
|
||||||
image: node:18
|
image: node:20
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/data
|
- ./:/data
|
||||||
- ./tmp:/tmp
|
- ./tmp:/tmp
|
||||||
- ./tmp/nonexistent:/nonexistent
|
- ./tmp/nonexistent:/nonexistent
|
||||||
|
- ./tmp/.npm:/.npm
|
||||||
|
- ./tmp/.yarn:/.yarn
|
||||||
working_dir: /data/docs
|
working_dir: /data/docs
|
||||||
command: sh -c "yarn install && yarn docpress:serve"
|
command: sh -c "yarn install && yarn docpress:serve"
|
||||||
expose:
|
expose:
|
||||||
@ -23,11 +25,13 @@ services:
|
|||||||
profiles:
|
profiles:
|
||||||
- tibi
|
- tibi
|
||||||
- tibi-dev
|
- tibi-dev
|
||||||
image: node:18
|
image: node:20
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/data
|
- ./:/data
|
||||||
- ./tmp:/tmp
|
- ./tmp:/tmp
|
||||||
- ./tmp/nonexistent:/nonexistent
|
- ./tmp/nonexistent:/nonexistent
|
||||||
|
- ./tmp/.npm:/.npm
|
||||||
|
- ./tmp/.yarn:/.yarn
|
||||||
working_dir: /data
|
working_dir: /data
|
||||||
command: sh -c "yarn install && API_BASE=http://tibiserver:8080/api/v1/_/${TIBI_NAMESPACE} yarn start"
|
command: sh -c "yarn install && API_BASE=http://tibiserver:8080/api/v1/_/${TIBI_NAMESPACE} yarn start"
|
||||||
expose:
|
expose:
|
||||||
@ -111,7 +115,7 @@ services:
|
|||||||
tibiadmin-dev:
|
tibiadmin-dev:
|
||||||
profiles:
|
profiles:
|
||||||
- tibi-dev
|
- tibi-dev
|
||||||
image: node:18
|
image: node:20
|
||||||
volumes:
|
volumes:
|
||||||
- ./../../cms/tibi-admin:/data
|
- ./../../cms/tibi-admin:/data
|
||||||
working_dir: /data
|
working_dir: /data
|
||||||
|
@ -29,7 +29,7 @@ const distDir = frontendDir + "/dist"
|
|||||||
const svelteConfig = require("./svelte.config")
|
const svelteConfig = require("./svelte.config")
|
||||||
const esbuildSvelte = sveltePlugin({
|
const esbuildSvelte = sveltePlugin({
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
css: false,
|
css: "external",
|
||||||
hydratable: true,
|
hydratable: true,
|
||||||
dev: (process.argv?.length > 2 ? process.argv[2] : "build") !== "build",
|
dev: (process.argv?.length > 2 ? process.argv[2] : "build") !== "build",
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,7 @@ config.options.plugins = [
|
|||||||
config.sveltePlugin({
|
config.sveltePlugin({
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
generate: "ssr",
|
generate: "ssr",
|
||||||
css: false,
|
css: "external",
|
||||||
hydratable: true,
|
hydratable: true,
|
||||||
dev: (process.argv?.length > 2 ? process.argv[2] : "build") !== "build",
|
dev: (process.argv?.length > 2 ? process.argv[2] : "build") !== "build",
|
||||||
},
|
},
|
||||||
|
@ -9,8 +9,22 @@ DirectoryIndex noindex
|
|||||||
|
|
||||||
RewriteRule ^/?api/(.*)$ http://tibi-server:8080/api/v1/_/demo/$1 [P,QSA,L]
|
RewriteRule ^/?api/(.*)$ http://tibi-server:8080/api/v1/_/demo/$1 [P,QSA,L]
|
||||||
|
|
||||||
|
# set in vhost or global in apache
|
||||||
|
#SSLProxyEngine On
|
||||||
|
#SSLProxyVerify none
|
||||||
|
#SSLProxyCheckPeerCN off
|
||||||
|
#SSLProxyCheckPeerName off
|
||||||
|
#SSLProxyCheckPeerExpire off
|
||||||
|
|
||||||
|
# Set the Host header for requests to sentry
|
||||||
|
RequestHeader set Host sentry.basehosts.de env=proxy-sentry
|
||||||
|
RequestHeader unset Authorization env=proxy-sentry
|
||||||
|
# need to update project id
|
||||||
|
RewriteRule ^/?_s(.*)$ https://sentry.basehosts.de/api/__PROJECT_ID__/envelope/$1 [P,L,E=proxy-sentry:1]
|
||||||
|
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-d
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
RewriteRule ^/?(.*)$ http://tibi-server:8080/api/v1/_/demo/ssr?token=owshwerNwoa&url=/$1 [P,QSA,L]
|
RewriteRule ^/?(.*)$ http://tibi-server:8080/api/v1/_/demo/ssr?token=owshwerNwoa&url=/$1 [P,QSA,L]
|
||||||
#RewriteRule (.*) /spa.html [QSA,L]
|
#RewriteRule (.*) /spa.html [QSA,L]
|
||||||
|
|
||||||
</ifModule>
|
</ifModule>
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
|
import * as sentry from "./sentry"
|
||||||
import configClient from "../../api/hooks/config-client"
|
import configClient from "../../api/hooks/config-client"
|
||||||
|
|
||||||
export const apiBaseURL = "/api/"
|
export const apiBaseURL = "/api/"
|
||||||
export const release = configClient.release
|
export const release = configClient.release
|
||||||
console.log("Release: ", release)
|
console.log("Release: ", release)
|
||||||
|
|
||||||
|
export const sentryDSN = "https://5063f9b5564d0fdece4e47a8e2e63672@sentry.basehosts.de/3"
|
||||||
|
export const sentryTracingOrigins = ["localhost", "project-domain.tld", /^\//]
|
||||||
|
export const sentryEnvironment: string = "local"
|
||||||
|
// need to execute early for fetch wrapping
|
||||||
|
// sentry.init(sentryDSN, sentryTracingOrigins, sentryEnvironment, release)
|
||||||
|
42
frontend/src/sentry.ts
Normal file
42
frontend/src/sentry.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import * as Sentry from "@sentry/svelte"
|
||||||
|
|
||||||
|
let initialized = false
|
||||||
|
|
||||||
|
export const init = (dsn: string, tracingOrigins: (string | RegExp)[], environment: string, release: string) => {
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
Sentry.init({
|
||||||
|
dsn: dsn,
|
||||||
|
tunnel: "/_s",
|
||||||
|
integrations: [
|
||||||
|
new Sentry.BrowserTracing({
|
||||||
|
tracingOrigins: tracingOrigins,
|
||||||
|
traceFetch: false,
|
||||||
|
traceXHR: false,
|
||||||
|
}),
|
||||||
|
new Sentry.Replay({
|
||||||
|
maskAllText: false,
|
||||||
|
maskAllInputs: false,
|
||||||
|
blockAllMedia: false,
|
||||||
|
networkDetailAllowUrls: [/\/api\//],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
environment: environment,
|
||||||
|
tracesSampleRate: 1.0,
|
||||||
|
debug: false,
|
||||||
|
release: release,
|
||||||
|
replaysSessionSampleRate: 1.0,
|
||||||
|
replaysOnErrorSampleRate: 1.0,
|
||||||
|
})
|
||||||
|
console.log("Sentry initialized")
|
||||||
|
initialized = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const currentTransaction = () => Sentry.getCurrentHub().getScope().getTransaction()
|
||||||
|
|
||||||
|
export const setUser = (user: Sentry.User) => {
|
||||||
|
if (typeof window !== "undefined" && initialized) {
|
||||||
|
user.ip_address = "{{auto}}"
|
||||||
|
Sentry.setUser(user)
|
||||||
|
}
|
||||||
|
}
|
49
package.json
49
package.json
@ -17,37 +17,36 @@
|
|||||||
"upload:sourcemaps": "scripts/upload-sourcemaps.sh"
|
"upload:sourcemaps": "scripts/upload-sourcemaps.sh"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.21.0",
|
"@babel/cli": "^7.23.0",
|
||||||
"@babel/core": "^7.21.0",
|
"@babel/core": "^7.23.3",
|
||||||
"@babel/preset-env": "^7.20.2",
|
"@babel/preset-env": "^7.23.3",
|
||||||
"@tsconfig/svelte": "^3.0.0",
|
"@tsconfig/svelte": "^5.0.2",
|
||||||
"@types/lodash": "^4.14.191",
|
"@types/lodash": "^4.14.201",
|
||||||
"browser-sync": "^2.27.11",
|
"browser-sync": "^2.29.3",
|
||||||
"chokidar": "^3.5.3",
|
"chokidar": "^3.5.3",
|
||||||
"connect-history-api-fallback": "^2.0.0",
|
"connect-history-api-fallback": "^2.0.0",
|
||||||
"esbuild": "^0.17.10",
|
"esbuild": "^0.19.5",
|
||||||
"esbuild-svelte": "^0.7.3",
|
"esbuild-svelte": "^0.8.0",
|
||||||
"http-proxy-middleware": "^2.0.6",
|
"http-proxy-middleware": "^2.0.6",
|
||||||
"less": "^4.1.3",
|
"less": "^4.2.0",
|
||||||
"morgan": "^1.10.0",
|
"morgan": "^1.10.0",
|
||||||
"node-fetch": "^3.3.0",
|
"node-fetch": "^3.3.2",
|
||||||
"postcss": "^8.4.21",
|
"postcss": "^8.4.31",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^3.1.0",
|
||||||
"prettier-plugin-svelte": "^2.9.0",
|
"prettier-plugin-svelte": "^3.1.0",
|
||||||
"sass": "^1.58.3",
|
"sass": "^1.69.5",
|
||||||
"svelte": "^3.55.1",
|
"svelte": "^4.2.3",
|
||||||
"svelte-check": "^3.0.3",
|
"svelte-check": "^3.6.0",
|
||||||
"svelte-hmr": "^0.15.1",
|
"svelte-hmr": "^0.15.3",
|
||||||
"svelte-preprocess": "^5.0.1",
|
"svelte-preprocess": "^5.1.0",
|
||||||
"svelte-preprocess-esbuild": "^3.0.1",
|
"svelte-preprocess-esbuild": "^3.0.1",
|
||||||
"svelte-routing": "^1.6.0",
|
"svelte-routing": "^2.6.0",
|
||||||
"tslib": "^2.5.0",
|
"tslib": "^2.6.2",
|
||||||
"typescript": "^4.9.5"
|
"typescript": "^5.2.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sentry/browser": "^7.38.0",
|
"@sentry/cli": "^2.21.4",
|
||||||
"@sentry/cli": "^2.13.0",
|
"@sentry/svelte": "^7.80.1",
|
||||||
"@sentry/tracing": "^7.38.0",
|
"core-js": "3.33.2"
|
||||||
"core-js": "3.28.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"useDefineForClassFields": true,
|
"useDefineForClassFields": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"importsNotUsedAsValues": "error",
|
"verbatimModuleSyntax": true,
|
||||||
"preserveValueImports": true,
|
|
||||||
|
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"checkJs": true
|
"checkJs": true
|
||||||
|
27
types/global.d.ts
vendored
Normal file
27
types/global.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
interface Ssr {
|
||||||
|
id?: string
|
||||||
|
path: string
|
||||||
|
content: string
|
||||||
|
validUntil: any // go Time
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiOptions {
|
||||||
|
method?: string
|
||||||
|
filter?: any
|
||||||
|
sort?: string
|
||||||
|
lookup?: string
|
||||||
|
limit?: number
|
||||||
|
offset?: number
|
||||||
|
projection?: string
|
||||||
|
headers?: {
|
||||||
|
[key: string]: string
|
||||||
|
}
|
||||||
|
params?: {
|
||||||
|
[key: string]: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiResult<T> {
|
||||||
|
data: T
|
||||||
|
count: number
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user