我们有一个很好的小应用程序,它运行良好,然后被要求将其转变为组织中的其他人可以利用的东西……这破坏了一切。我们有一个简单的Express服务器,其中包含一些api路由以及服务的react应用。
最初,我们将使用以下网址格式访问我们的应用程序:https://our_team_name.company.com/app_name/
我们曾表达过对以下路线的倾听:
// server.js:
import "./env";
import app from "app";
import { logger } from "@company/shared-code";
let fs = require("fs");
let https = require("https");
let privateKey = fs.readFileSync(`${process.env.CERT_HOME}/server.key`, "utf8");
let certificate = fs.readFileSync(`${process.env.CERT_HOME}/server.crt`, "utf8");
let credentials = { key: privateKey, cert: certificate };
let httpsServer = https.createServer(credentials, app);
httpsServer.listen(process.env.PORT || 3000, function () {
logger.info("Application listening on port " + (process.env.PORT || 3000) + "!");
});
// app.js:
import express from "express";
import health from "./routes/health/health.js";
const app = express();
app.use("/app_name/rest/health", health);
app.use(express.static(path.join(process.cwd(), "build")));
app.get("/app_name/ui*", function(req, res) {
res.sendFile(path.join(process.cwd(), "build", "index.html"));
});
// health.js:
import express from "express";
import os from "os";
import Promise from "bluebird";
const disk = Promise.promisifyAll(require("diskusage"));
const health = express.Router();
health.get("*", async (req, res) => {
const { available, total } = await disk.checkAsync(os.platform() === "win32" ? "c:" : "/");
try {
res.send({
timestamp: Date.now(),
results: [
{
testName: "System",
status: "OK",
message: "System Information",
platform: os.platform(),
processing: {
architecture: os.arch(),
cpu: {
count: os.cpus().length,
cpus: os.cpus(),
},
avgLoad: os.loadavg(),
},
memory: {
totalMemory: (os.totalmem() / 1000000000).toFixed(2) + "GB",
freeMemory: (os.freemem() / 1000000000).toFixed(2) + "GB",
},
disk: {
available: (available / 1000000000).toFixed(2) + "GB",
total: (total / 1000000000).toFixed(2) + "GB",
percentFull: (((total - available) / total) * 100).toFixed(2) + "%",
},
},
],
status: "OK",
});
} catch (err) {
res.status(520).send({
err,
});
}
});
export default health;
Express捕获了“其余”路由(例如 https://our_team_name.company.com/app_name/rest/health )并投放了内容,它捕获了“ ui”路由并投放了index.html,对路由器进行了响应以处理客户端路由,每个人都很高兴。
为了使我们能够向利用此功能的新团队提供适当的证书,我们获得了覆盖* .technology.company.com / app_name /的新通配符证书,以便下一个团队可以分叉存储库并进行部署而无需获得新证书...很棒。
我们对这项新配置所做的出色工作和部署表示祝贺。但是,导航到https://our_team_name.technology.company.com/app_name/时,现在似乎每条路线都由get(“ / app_name / ui *”)服务...尽管花了太多时间来调试它,但我一直无法理解为什么我的“其余”路由不合格,甚至无法通过本地主机重新创建此行为。
当前正在请求 https://our_team_name.technology.company.com/app_name/rest/health 的响应是index.html,并且从未调用运行状况路由。
有人遇到这样的问题吗?
更新:添加了更多实施细节
答案 0 :(得分:0)
create-react-app服务工作程序试图以一种意外的方式缓存资源,从而导致实际上并未调用express ...解决方案是对服务工作程序的更新