generated from cms/tibi-docs
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const fs = require("fs")
|
||||
|
||||
const resolvePlugin = {
|
||||
name: "resolvePlugin",
|
||||
setup(build) {
|
||||
@@ -68,7 +70,9 @@ const bsMiddleware = []
|
||||
|
||||
if (process.argv[2] == "start") {
|
||||
const { createProxyMiddleware } = require("http-proxy-middleware")
|
||||
const apiBase = process.env.API_BASE || "http://localhost:8080/api/v1/_/" + process.env.NAMESPACE
|
||||
const dotEnv = fs.readFileSync(__dirname + "/.env", "utf8")
|
||||
const TIBI_NAMESPACE = dotEnv.match(/TIBI_NAMESPACE=(.*)/)[1]
|
||||
const apiBase = process.env.API_BASE || "http://localhost:8080/api/v1/_/" + TIBI_NAMESPACE
|
||||
bsMiddleware.push(
|
||||
createProxyMiddleware("/api", {
|
||||
target: apiBase,
|
||||
@@ -77,12 +81,39 @@ if (process.argv[2] == "start") {
|
||||
logLevel: "debug",
|
||||
})
|
||||
)
|
||||
|
||||
// if SSR env variable is set
|
||||
console.log(process.env, "=========================ENV")
|
||||
if (process.env.SSR) {
|
||||
// read api/config.yml.env and read SSR_TOKEN variable from it
|
||||
const configEnv = fs.readFileSync(__dirname + "/api/config.yml.env", "utf8")
|
||||
const SSR_TOKEN = configEnv.match(/SSR_TOKEN=(.*)/)[1]
|
||||
|
||||
// redirect all other requests to /api/ssr?token=owshwerNwoa&url=...
|
||||
bsMiddleware.push(
|
||||
createProxyMiddleware(
|
||||
function (path, req) {
|
||||
return !path.match(/\./)
|
||||
},
|
||||
{
|
||||
target: apiBase,
|
||||
changeOrigin: true,
|
||||
logLevel: "debug",
|
||||
pathRewrite: function (path, req) {
|
||||
console.log(path)
|
||||
return "/ssr?token=" + SSR_TOKEN + "&url=" + encodeURIComponent(path)
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sveltePlugin: sveltePlugin,
|
||||
resolvePlugin: resolvePlugin,
|
||||
options: options,
|
||||
distDir,
|
||||
watch: {
|
||||
path: [__dirname + "/" + frontendDir + "/src/**/*"],
|
||||
},
|
||||
@@ -103,7 +134,6 @@ module.exports = {
|
||||
}),
|
||||
],
|
||||
},
|
||||
ghostMode: false,
|
||||
open: false,
|
||||
// logLevel: "debug",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user