1
0
mirror of https://github.com/ZeroCatDev/ClassworksKV.git synced 2025-07-01 20:09:23 +00:00

Refactor app.js to streamline routing by removing unused API endpoints and integrating the KV store router directly. Clean up errorHandler.js by removing unnecessary comments and imports.

This commit is contained in:
SunWuyuan 2025-05-10 13:50:19 +08:00
parent eeacc317a9
commit 4c8e38e805
No known key found for this signature in database
GPG Key ID: A6A54CF66F56BB64
2 changed files with 1 additions and 26 deletions

22
app.js
View File

@ -6,7 +6,6 @@ import logger from "morgan";
import bodyParser from "body-parser";
import errorHandler from "./middleware/errorHandler.js";
import errors from "./utils/errors.js";
import kvStore from "./models/kvStore.js";
import { initReadme, getReadmeValue } from "./utils/siteinfo.js";
import kvRouter from "./routes/kv.js";
@ -59,28 +58,9 @@ app.use((req, res, next) => {
app.get("/", (req, res) => {
res.render("index.ejs", { readmeValue: getReadmeValue() });
});
// API test endpoint
app.get(
"/api/test",
errors.catchAsync((req, res) => {
res.json({
status: "success",
message: "API is running",
time: new Date().getTime(),
});
})
);
// Mount the KV store router
app.use("/api/kv", kvRouter);
// Test view
app.get(
"/test",
errors.catchAsync(async (req, res) => {
res.render("test.ejs");
})
);
app.use("/", kvRouter);
// 兜底404路由 - 处理所有未匹配的路由
app.use((req, res, next) => {

View File

@ -1,8 +1,3 @@
/**
* 全局错误处理中间件
* 简化版本 - 统一错误响应格式
*/
import errors from "../utils/errors.js";
import { isDevelopment } from "../config.js";
const errorHandler = (err, req, res, next) => {