-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbb239c
commit d01d977
Showing
4 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export default defineNuxtConfig({ | ||
modules: ["../src/module"], | ||
nuxtServerUtils: {}, | ||
nuxtServerUtils: { | ||
mongodbUri: process.env.MONGODB_URI, | ||
}, | ||
devtools: { enabled: true }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { allows } from "#nuxt-server-utils"; | ||
import { Authorizer } from "#nuxt-server-utils"; | ||
import { defineEventHandler } from "#imports"; | ||
|
||
export default defineEventHandler((event) => { | ||
allows(event, () => false); | ||
|
||
Authorizer.allows(event, () => true, "You are not allowed"); | ||
return `Gate passed`; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { NitroApp } from "nitropack"; | ||
import mongoose from "mongoose"; | ||
import { logger } from "@nuxt/kit"; | ||
import { useRuntimeConfig } from "#imports"; | ||
|
||
type NitroAppPlugin = (nitro: NitroApp) => void; | ||
|
||
function defineNitroPlugin(def: NitroAppPlugin): NitroAppPlugin { | ||
return def; | ||
} | ||
|
||
export default defineNitroPlugin(async (app: NitroApp) => { | ||
const config = useRuntimeConfig(); | ||
|
||
if (!config.nuxtServerUtils?.mongodbUri) { | ||
logger.warn( | ||
"Mongodb URI not found in runtime config, skipping mongodb connection" | ||
); | ||
return; | ||
} | ||
try { | ||
await mongoose.connect(config.nuxtServerUtils.mongodbUri); | ||
logger.info("Mongodb connected"); | ||
} catch (e) { | ||
logger.error("Mongodb connection error: ", e); | ||
} | ||
}); |