-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (51 loc) · 1.69 KB
/
index.js
File metadata and controls
63 lines (51 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import express from "express";
import { microsubController } from "./lib/controllers/microsub.js";
import { createIndexes } from "./lib/storage/items.js";
const defaults = {
mountPath: "/microsub",
};
const router = express.Router();
export default class MicrosubEndpoint {
name = "Microsub endpoint";
/**
* @param {object} options - Plugin options
* @param {string} [options.mountPath] - Path to mount Microsub endpoint
*/
constructor(options = {}) {
this.options = { ...defaults, ...options };
this.mountPath = this.options.mountPath;
}
/**
* Microsub API routes (authenticated)
* @returns {import("express").Router} Express router
*/
get routes() {
// Main Microsub endpoint - dispatches based on action parameter
router.get("/", microsubController.get);
router.post("/", microsubController.post);
return router;
}
/**
* Initialize plugin
* @param {object} indiekit - Indiekit instance
*/
init(indiekit) {
console.info("[Microsub] Initializing endpoint-microsub plugin");
// Register MongoDB collections
indiekit.addCollection("microsub_channels");
indiekit.addCollection("microsub_items");
console.info("[Microsub] Registered MongoDB collections");
// Register endpoint
indiekit.addEndpoint(this);
// Set microsub endpoint URL in config
if (!indiekit.config.application.microsubEndpoint) {
indiekit.config.application.microsubEndpoint = this.mountPath;
}
// Create indexes for optimal performance (runs in background)
if (indiekit.database) {
createIndexes(indiekit).catch((error) => {
console.warn("[Microsub] Index creation failed:", error.message);
});
}
}
}