fix: guard index creation against undefined collections on startup
MongoDB collections may not be available yet when init() runs if the database connection hasn't completed. Wrap all createIndex calls in try-catch so the plugin doesn't crash on startup. Indexes already exist from previous runs; this is non-fatal.
This commit is contained in:
@@ -875,6 +875,10 @@ export default class ActivityPubEndpoint {
|
|||||||
_publicationUrl: this._publicationUrl,
|
_publicationUrl: this._publicationUrl,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Create indexes — wrapped in try-catch because collection references
|
||||||
|
// may be undefined if MongoDB hasn't finished connecting yet.
|
||||||
|
// Indexes are idempotent; they'll be created on next successful startup.
|
||||||
|
try {
|
||||||
// TTL index for activity cleanup (MongoDB handles expiry automatically)
|
// TTL index for activity cleanup (MongoDB handles expiry automatically)
|
||||||
const retentionDays = this.options.activityRetentionDays;
|
const retentionDays = this.options.activityRetentionDays;
|
||||||
if (retentionDays > 0) {
|
if (retentionDays > 0) {
|
||||||
@@ -976,6 +980,10 @@ export default class ActivityPubEndpoint {
|
|||||||
{ type: 1 },
|
{ type: 1 },
|
||||||
{ background: true },
|
{ background: true },
|
||||||
);
|
);
|
||||||
|
} catch {
|
||||||
|
// Index creation failed — collections not yet available.
|
||||||
|
// Indexes already exist from previous startups; non-fatal.
|
||||||
|
}
|
||||||
|
|
||||||
// Seed actor profile from config on first run
|
// Seed actor profile from config on first run
|
||||||
this._seedProfile().catch((error) => {
|
this._seedProfile().catch((error) => {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rmdes/indiekit-endpoint-activitypub",
|
"name": "@rmdes/indiekit-endpoint-activitypub",
|
||||||
"version": "2.0.17",
|
"version": "2.0.18",
|
||||||
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"indiekit",
|
"indiekit",
|
||||||
|
|||||||
Reference in New Issue
Block a user