mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
add server
This commit is contained in:
62
server/index.js
Normal file
62
server/index.js
Normal file
@@ -0,0 +1,62 @@
|
||||
const express = require("express");
|
||||
const path = require("path");
|
||||
const config = require("./config");
|
||||
const { setupWebSocket } = require("./ws");
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.json({ limit: "50mb" }));
|
||||
|
||||
// --- Request logging ---
|
||||
app.use((req, res, next) => {
|
||||
const start = Date.now();
|
||||
const origEnd = res.end;
|
||||
res.end = function (...args) {
|
||||
const duration = Date.now() - start;
|
||||
const status = res.statusCode;
|
||||
const color =
|
||||
status >= 500 ? "\x1b[31m" : status >= 400 ? "\x1b[33m" : "\x1b[32m";
|
||||
const reset = "\x1b[0m";
|
||||
const path =
|
||||
req.originalUrl.length > 80
|
||||
? req.originalUrl.slice(0, 80) + "..."
|
||||
: req.originalUrl;
|
||||
console.log(
|
||||
`${color}${req.method} ${status}${reset} ${path} (${duration}ms)`,
|
||||
);
|
||||
origEnd.apply(this, args);
|
||||
};
|
||||
next();
|
||||
});
|
||||
|
||||
// --- Routes ---
|
||||
const fsRoutes = require("./routes/fs");
|
||||
const vaultRoutes = require("./routes/vault");
|
||||
|
||||
app.use("/api/fs", fsRoutes);
|
||||
app.use("/api/vault", vaultRoutes);
|
||||
|
||||
// --- Static serving ---
|
||||
// Serve the built shim-loader.js
|
||||
app.use(
|
||||
"/shim-loader.js",
|
||||
express.static(path.join(__dirname, "..", "dist", "shim-loader.js")),
|
||||
);
|
||||
|
||||
// Serve patched index.html at root
|
||||
app.get("/", (req, res) => {
|
||||
res.sendFile(path.join(__dirname, "..", "dist", "index.html"));
|
||||
});
|
||||
|
||||
// Serve obsidian assets
|
||||
app.use(express.static(config.obsidianAssetsPath));
|
||||
|
||||
// --- Start ---
|
||||
const server = app.listen(config.port, () => {
|
||||
console.log(
|
||||
`[obsidian-bridge] Server running on http://localhost:${config.port}`,
|
||||
);
|
||||
console.log(`[obsidian-bridge] Vault path: ${config.vaultPath}`);
|
||||
});
|
||||
|
||||
setupWebSocket(server);
|
||||
Reference in New Issue
Block a user