Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 66c08e5d52 | |||
| 774d4b6243 | |||
| 86c3c2954e | |||
| 205435e546 | |||
| cf48c2b6df | |||
| ac24680bd4 | |||
| d381058591 | |||
| cfc7ea59b8 | |||
| b4fa9f5617 | |||
| c967d0bb16 | |||
| c8bcc9c488 | |||
| f00819768e | |||
| e0f56dfa38 | |||
| ecac456a4a |
57
CHANGELOG.md
57
CHANGELOG.md
@ -1,6 +1,63 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
|
||||||
|
## v0.0.7
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.6...v0.0.7)
|
||||||
|
|
||||||
|
|
||||||
|
### 🚀 Enhancements
|
||||||
|
|
||||||
|
- Auto-import schema files ([205435e](https://github.com/arashsheyda/nuxt-mongoose/commit/205435e))
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Mongoose config ([cf48c2b](https://github.com/arashsheyda/nuxt-mongoose/commit/cf48c2b))
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- Improve logger message ([86c3c29](https://github.com/arashsheyda/nuxt-mongoose/commit/86c3c29))
|
||||||
|
- Update dependencies ([774d4b6](https://github.com/arashsheyda/nuxt-mongoose/commit/774d4b6))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arashsheyda <sheidaeearash1999@gmail.com>
|
||||||
|
|
||||||
|
## v0.0.6
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.5...v0.0.6)
|
||||||
|
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Remove useMongoose composable ([d381058](https://github.com/arashsheyda/nuxt-mongoose/commit/d381058))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arashsheyda <sheidaeearash1999@gmail.com>
|
||||||
|
|
||||||
|
## v0.0.5
|
||||||
|
|
||||||
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.4...v0.0.5)
|
||||||
|
|
||||||
|
|
||||||
|
### 🩹 Fixes
|
||||||
|
|
||||||
|
- Update readme ([e0f56df](https://github.com/arashsheyda/nuxt-mongoose/commit/e0f56df))
|
||||||
|
- Add brackets ([f008197](https://github.com/arashsheyda/nuxt-mongoose/commit/f008197))
|
||||||
|
- Update logo ([c8bcc9c](https://github.com/arashsheyda/nuxt-mongoose/commit/c8bcc9c))
|
||||||
|
- Update icon link ([c967d0b](https://github.com/arashsheyda/nuxt-mongoose/commit/c967d0b))
|
||||||
|
- Update icon link ([b4fa9f5](https://github.com/arashsheyda/nuxt-mongoose/commit/b4fa9f5))
|
||||||
|
|
||||||
|
### 🏡 Chore
|
||||||
|
|
||||||
|
- Update dependencies ([ecac456](https://github.com/arashsheyda/nuxt-mongoose/commit/ecac456))
|
||||||
|
|
||||||
|
### ❤️ Contributors
|
||||||
|
|
||||||
|
- Arashsheyda <sheidaeearash1999@gmail.com>
|
||||||
|
- Arash
|
||||||
|
|
||||||
## v0.0.4
|
## v0.0.4
|
||||||
|
|
||||||
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.3...v0.0.4)
|
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v0.0.3...v0.0.4)
|
||||||
|
|||||||
18
README.md
18
README.md
@ -1,4 +1,4 @@
|
|||||||

|

|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<h1>Nuxt Mongoose</h1>
|
<h1>Nuxt Mongoose</h1>
|
||||||
@ -10,7 +10,7 @@
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm add nuxt-mongoose mongoose
|
pnpm add nuxt-mongoose
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -36,10 +36,13 @@ export default defineNuxtConfig({
|
|||||||
mongoose: {
|
mongoose: {
|
||||||
uri: 'process.env.MONGODB_URI',
|
uri: 'process.env.MONGODB_URI',
|
||||||
options: {},
|
options: {},
|
||||||
|
modelsDir: 'models',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
by default, `nuxt-mongoose` will auto-import your schemas from the `models` directory from `server` directory. You can change this behavior by setting the `modelsDir` option.
|
||||||
|
|
||||||
* for more information about the options, please refer to the [Mongoose documentation](https://mongoosejs.com/docs/connections.html#options). *
|
* for more information about the options, please refer to the [Mongoose documentation](https://mongoosejs.com/docs/connections.html#options). *
|
||||||
|
|
||||||
## API
|
## API
|
||||||
@ -83,17 +86,6 @@ export const User = defineMongooseModel({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### useMongoose
|
|
||||||
|
|
||||||
This composable returns the Mongoose DB instance. Example usage:
|
|
||||||
|
|
||||||
```vue
|
|
||||||
<script lang="ts" setup>
|
|
||||||
const mongoose = useMongoose()
|
|
||||||
const user = await mongoose.db.collection('users').findOne()
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT License](./LICENSE)
|
[MIT License](./LICENSE)
|
||||||
|
|||||||
@ -1,26 +1,26 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Generator: Adobe Illustrator 25.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
<!-- Generator: Adobe Illustrator 25.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
viewBox="0 0 914.6 296.6" style="enable-background:new 0 0 914.6 296.6;" xml:space="preserve">
|
viewBox="0 0 520.1 232.7" style="enable-background:new 0 0 520.1 232.7;" xml:space="preserve">
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.st0{fill:#880000;}
|
.st0{fill:#880000;}
|
||||||
.st1{fill:#00DC82;}
|
.st1{fill:#00DC82;}
|
||||||
</style>
|
</style>
|
||||||
<path class="st0" d="M620,225.4c-47.8-6.5-96.2,6.6-134.1,36.4c-9.7-24.4-21.2-48-34.1-70.8c-10.8-19.1-18.1-29.1-28.6-29.9
|
<path class="st0" d="M323.9,193.5c-47.8-6.5-96.2,6.6-134.1,36.4c-9.7-24.3-21.1-48-34.1-70.8c-10.8-19.1-18.1-29.1-28.6-29.9
|
||||||
c-10.5-0.8-21.3,9.9-25.3,15c-2.4-6.3-11.1-27-25.7-28.6c-14.6-1.6-26.7,16.2-41.7,38c-12.2,17.8-22,37.1-29.3,57.4
|
s-21.3,9.9-25.3,15C94,126,82.2,113.3,71.2,114.3c-6.5,0.6-12,7.6-22.6,21.5C38.3,149.5,31,161.7,25,172.5
|
||||||
c-4.9-14.1-18.2-46.7-51.4-69.3c-42.6-28.9-100.8-29.7-151.2-3.2c82.8-70,172.3-122.4,284.9-120c10.8,56.5,46.3,100.5,79.8,105.9
|
c-5.4,9.7-12.4,22.7-19.9,38.5C5.3,133.1,6,75,5.8,49.3c0-4.6-0.1-15.1,6.8-22.9c7.3-8.2,18.6-9.1,34.2-10.2
|
||||||
c-14.4-13.7-33.3-29-48.6-47.3c-13.2-15.6-21.3-34.8-21-56.6c0.2-12.6,5.8-19.8,17.5-18.2c23.3,3.5,46.3,8.9,69.3,13.6
|
c9.6-0.7,23.6-0.8,40.5,2.3c1.2,12,8.2,42,31.4,72.1c14.4,18.7,31.7,31.1,48.4,33.8c-14.4-13.7-33.3-29-48.6-47.3
|
||||||
c2.5,0.5,4.9,1.7,8.4,0.5l-23.2-11.5c0.4-1.4,0.7-2.8,1.1-4.2c114.6-5.8,221.8,26,328.4,65.5c-1.4,7.4-2.5,12.9-3.6,18.4l1.5,0.6
|
c-13.2-15.6-21.3-34.8-21-56.6c0.2-12.6,5.8-19.8,17.5-18.2c23.3,3.5,46.3,8.9,69.3,13.6c2.5,0.5,4.9,1.7,8.4,0.5L169.6,4.9
|
||||||
l7.1-14c16.3,2.2,18.3,6.4,14.1,20.7c-7.4,25.7-24.1,39.2-50,44.1c-41.3,7.9-82.2,17.2-123.5,25.3
|
c0.4-1.4,0.7-2.8,1.1-4.2c114.6-5.8,221.8,26,328.4,65.5c-1.4,7.4-2.5,12.9-3.6,18.4l1.5,0.6l7.1-14c16.3,2.2,18.3,6.4,14.1,20.7
|
||||||
C614.3,198.5,613.4,199.4,620,225.4z M481.1,94.6c-16.8-20-51.7-37.3-67.5-34.9c-2.3,22.4,34.4,68.2,57.8,71.7
|
c-7.4,25.7-24.1,39.2-50,44.1c-41.3,7.9-82.2,17.2-123.5,25.3C318.2,166.6,317.3,167.5,323.9,193.5z M185,62.7
|
||||||
c-2.7-4.4-5.3-8.4-7.8-12.6l6.4-3.5c-4.6-6-8.8-11.4-15.2-19.8l18.7,7.9l-6.6-13.7L481.1,94.6z M672,98.1l0.2-4.8l-90.4-17.4
|
c-16.8-20-51.7-37.3-67.5-34.9c-2.3,22.4,34.4,68.2,57.8,71.7c-2.7-4.4-5.3-8.4-7.8-12.6l6.4-3.5l-15.2-19.8l18.7,7.9l-6.6-13.7
|
||||||
l-1.3,4.5c14.2,7,27.8,16.7,42.8,20.2C639.4,104.2,656.2,103.4,672,98.1L672,98.1z M659.4,162.1l-1.6-4.3
|
L185,62.7z M375.9,66.2l0.2-4.8L285.7,44l-1.3,4.5c14.2,7,27.8,16.7,42.8,20.2C343.4,72.3,360.2,71.5,375.9,66.2L375.9,66.2z
|
||||||
c-20.4,8.3-41.2,15.8-61,25.3c-11.1,5.3-10.9,14-3,22.5C601.6,170.5,636.4,174.7,659.4,162.1L659.4,162.1z"/>
|
M363.3,130.2l-1.6-4.3c-20.4,8.3-41.2,15.8-61,25.3c-11.1,5.3-10.9,14-3,22.5C305.5,138.6,340.3,142.8,363.3,130.2z"/>
|
||||||
<path class="st1" d="M399.5,264.6H459c1.9,0,3.8-0.5,5.4-1.4c3.3-1.9,5.3-5.4,5.3-9.3c0-1.9-0.5-3.7-1.4-5.3l-40-68.7
|
<path class="st1" d="M103.4,232.7h59.5c1.9,0,3.7-0.5,5.4-1.4c3.3-1.9,5.3-5.5,5.3-9.3c0-1.9-0.5-3.7-1.4-5.3l-40-68.7
|
||||||
c-0.9-1.6-2.3-2.9-3.9-3.8c-3.4-2-7.5-2-10.8,0c-1.6,0.9-3,2.3-3.9,3.8l-10.2,17.6l-20-34.4c-1-1.6-2.4-2.9-4-3.8
|
c-0.9-1.6-2.3-2.9-3.9-3.8c-3.3-2-7.5-2-10.8,0c-1.6,0.9-2.9,2.2-3.9,3.8l-10.2,17.6l-20-34.4c-1-1.6-2.4-2.9-4-3.8
|
||||||
c-3.3-2-7.5-2-10.7,0c-1.6,0.9-3,2.3-3.9,3.8L311,248.6c-0.9,1.6-1.5,3.5-1.5,5.3c0.1,3.8,2.1,7.3,5.4,9.3c1.6,0.9,3.5,1.4,5.4,1.4
|
c-3.3-2-7.4-2-10.7,0c-1.6,0.9-2.9,2.2-3.9,3.8l-49.9,85.5c-3,5-1.3,11.5,3.7,14.5c1.7,1,3.6,1.5,5.6,1.5h37.4
|
||||||
h37.4c14.7,0,25.7-6.4,33.3-19l18.2-31.4l9.8-16.7l29.3,50.4h-39.1L399.5,264.6z M357.1,247.8H331l39.1-67.1l19.5,33.6l-13.1,22.4
|
c14.7,0,25.7-6.4,33.3-19l18.2-31.4l9.8-16.7l29.3,50.4h-39.1L103.4,232.7z M61,215.9H34.9L74,148.8l19.5,33.6l-13.1,22.4
|
||||||
C371.6,244.9,365.9,247.8,357.1,247.8z"/>
|
C75.5,213,69.8,215.9,61,215.9L61,215.9z"/>
|
||||||
<path class="st1" d="M672,98.1l0.2-4.8l-90.4-17.4l-1.3,4.5c14.2,7,27.8,16.7,42.8,20.2C639.4,104.2,656.2,103.4,672,98.1L672,98.1z
|
<path class="st1" d="M375.9,66.2l0.2-4.8L285.7,44l-1.3,4.5c14.2,7,27.8,16.7,42.8,20.2C343.4,72.3,360.2,71.5,375.9,66.2
|
||||||
"/>
|
L375.9,66.2z"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
25
package.json
25
package.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "nuxt-mongoose",
|
"name": "nuxt-mongoose",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.0.4",
|
"version": "0.0.7",
|
||||||
"description": "Nuxt 3 module for MongoDB with Mongoose",
|
"description": "Nuxt 3 module for MongoDB with Mongoose",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -38,14 +38,15 @@
|
|||||||
"test:watch": "vitest watch"
|
"test:watch": "vitest watch"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxt/devtools-kit": "^0.4.2",
|
"@nuxt/devtools-kit": "^0.5.5",
|
||||||
"@nuxt/kit": "^3.4.2",
|
"@nuxt/kit": "^3.5.2",
|
||||||
"@types/fs-extra": "^11.0.1",
|
"@types/fs-extra": "^11.0.1",
|
||||||
"birpc": "^0.2.11",
|
"birpc": "^0.2.11",
|
||||||
"defu": "^6.1.2",
|
"defu": "^6.1.2",
|
||||||
"flatted": "^3.2.7",
|
"flatted": "^3.2.7",
|
||||||
"fs-extra": "^11.1.1",
|
"fs-extra": "^11.1.1",
|
||||||
"mongoose": "^7.0.5",
|
"mongoose": "^7.2.2",
|
||||||
|
"pathe": "^1.1.0",
|
||||||
"pluralize": "^8.0.0",
|
"pluralize": "^8.0.0",
|
||||||
"sirv": "^2.0.3",
|
"sirv": "^2.0.3",
|
||||||
"tinyws": "^0.1.0",
|
"tinyws": "^0.1.0",
|
||||||
@ -53,19 +54,19 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "^0.38.5",
|
"@antfu/eslint-config": "^0.38.5",
|
||||||
"@nuxt/devtools": "^0.4.2",
|
"@nuxt/devtools": "^0.5.5",
|
||||||
"@nuxt/devtools-ui-kit": "^0.4.2",
|
"@nuxt/devtools-ui-kit": "^0.5.5",
|
||||||
"@nuxt/module-builder": "^0.3.0",
|
"@nuxt/module-builder": "^0.4.0",
|
||||||
"@nuxt/schema": "^3.4.2",
|
"@nuxt/schema": "^3.5.2",
|
||||||
"@nuxt/test-utils": "^3.4.2",
|
"@nuxt/test-utils": "^3.5.2",
|
||||||
"@types/pluralize": "^0.0.29",
|
"@types/pluralize": "^0.0.29",
|
||||||
"@types/ws": "^8.5.4",
|
"@types/ws": "^8.5.4",
|
||||||
"changelogen": "^0.5.3",
|
"changelogen": "^0.5.3",
|
||||||
"eslint": "^8.39.0",
|
"eslint": "^8.39.0",
|
||||||
"nuxt": "^3.4.2",
|
"nuxt": "^3.5.2",
|
||||||
"sass": "^1.62.1",
|
"sass": "^1.62.1",
|
||||||
"sass-loader": "^13.2.2",
|
"sass-loader": "^13.3.1",
|
||||||
"splitpanes": "^3.1.5",
|
"splitpanes": "^3.1.5",
|
||||||
"vitest": "^0.30.1"
|
"vitest": "^0.31.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
5364
pnpm-lock.yaml
generated
5364
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,14 @@
|
|||||||
import { addImportsDir, addServerPlugin, addTemplate, createResolver, defineNuxtModule, logger } from '@nuxt/kit'
|
import {
|
||||||
|
addImportsDir,
|
||||||
|
addServerPlugin,
|
||||||
|
addTemplate,
|
||||||
|
createResolver,
|
||||||
|
defineNuxtModule,
|
||||||
|
logger,
|
||||||
|
} from '@nuxt/kit'
|
||||||
import { pathExists } from 'fs-extra'
|
import { pathExists } from 'fs-extra'
|
||||||
import { tinyws } from 'tinyws'
|
import { tinyws } from 'tinyws'
|
||||||
|
import { join } from 'pathe'
|
||||||
import { defu } from 'defu'
|
import { defu } from 'defu'
|
||||||
import sirv from 'sirv'
|
import sirv from 'sirv'
|
||||||
|
|
||||||
@ -9,6 +17,8 @@ import type { ModuleOptions } from './types'
|
|||||||
|
|
||||||
import { setupRPC } from './server-rpc'
|
import { setupRPC } from './server-rpc'
|
||||||
|
|
||||||
|
export type { ModuleOptions }
|
||||||
|
|
||||||
export default defineNuxtModule<ModuleOptions>({
|
export default defineNuxtModule<ModuleOptions>({
|
||||||
meta: {
|
meta: {
|
||||||
name: 'nuxt-mongoose',
|
name: 'nuxt-mongoose',
|
||||||
@ -18,20 +28,25 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
uri: process.env.MONGODB_URI as string,
|
uri: process.env.MONGODB_URI as string,
|
||||||
devtools: true,
|
devtools: true,
|
||||||
options: {},
|
options: {},
|
||||||
|
modelsDir: 'models',
|
||||||
},
|
},
|
||||||
setup(options, nuxt) {
|
setup(options, nuxt) {
|
||||||
const { resolve } = createResolver(import.meta.url)
|
const { resolve } = createResolver(import.meta.url)
|
||||||
|
const runtimeConfig = nuxt.options.runtimeConfig
|
||||||
|
|
||||||
addImportsDir(resolve('./runtime/composables'))
|
addImportsDir(resolve('./runtime/composables'))
|
||||||
|
|
||||||
if (!options.uri)
|
if (!options.uri) {
|
||||||
console.warn('Missing `MONGODB_URI` in `.env`')
|
logger.warn('Missing `MONGODB_URI` in `.env`')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Public runtimeConfig
|
// Runtime Config
|
||||||
nuxt.options.runtimeConfig.public.mongoose = defu(nuxt.options.runtimeConfig.public.mongoose || {}, {
|
runtimeConfig.mongoose = defu(runtimeConfig.mongoose || {}, {
|
||||||
uri: options.uri,
|
uri: options.uri,
|
||||||
options: options.options,
|
options: options.options,
|
||||||
devtools: options.devtools,
|
devtools: options.devtools,
|
||||||
|
modelsDir: options.modelsDir,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Setup devtools UI
|
// Setup devtools UI
|
||||||
@ -91,6 +106,16 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
options.references.push({ path: resolve(nuxt.options.buildDir, 'types/nuxt-mongoose.d.ts') })
|
options.references.push({ path: resolve(nuxt.options.buildDir, 'types/nuxt-mongoose.d.ts') })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Nitro auto imports
|
||||||
|
nuxt.hook('nitro:config', (_nitroConfig) => {
|
||||||
|
if (_nitroConfig.imports) {
|
||||||
|
_nitroConfig.imports.dirs = _nitroConfig.imports.dirs || []
|
||||||
|
_nitroConfig.imports.dirs?.push(
|
||||||
|
join(nuxt.options.serverDir, runtimeConfig.mongoose.modelsDir),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Add server-plugin for database connection
|
// Add server-plugin for database connection
|
||||||
addServerPlugin(resolve('./runtime/server/plugins/mongoose.db'))
|
addServerPlugin(resolve('./runtime/server/plugins/mongoose.db'))
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
import type { mongo } from 'mongoose'
|
|
||||||
import { connection } from 'mongoose'
|
|
||||||
|
|
||||||
export function useMongoose(): { db: mongo.Db } {
|
|
||||||
return {
|
|
||||||
db: connection?.db,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,13 +5,13 @@ import { logger } from '@nuxt/kit'
|
|||||||
import { useRuntimeConfig } from '#imports'
|
import { useRuntimeConfig } from '#imports'
|
||||||
|
|
||||||
export async function defineMongooseConnection({ uri, options }: { uri?: string; options?: ConnectOptions } = {}): Promise<void> {
|
export async function defineMongooseConnection({ uri, options }: { uri?: string; options?: ConnectOptions } = {}): Promise<void> {
|
||||||
const config = useRuntimeConfig().public.mongoose
|
const config = useRuntimeConfig().mongoose
|
||||||
const mongooseUri = uri || config.uri
|
const mongooseUri = uri || config.uri
|
||||||
const mongooseOptions = options || config.options
|
const mongooseOptions = options || config.options
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await mongoose.connect(mongooseUri, { ...mongooseOptions })
|
await mongoose.connect(mongooseUri, { ...mongooseOptions })
|
||||||
logger.info('Connected to database')
|
logger.info('Connected to mongoose database')
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
logger.error('Error connecting to database', err)
|
logger.error('Error connecting to database', err)
|
||||||
|
|||||||
@ -25,9 +25,9 @@ export function setupResourceRPC({ nuxt, rpc }: NuxtDevtoolsServerContext): any
|
|||||||
const routeTypes = {
|
const routeTypes = {
|
||||||
index: 'index.get.ts',
|
index: 'index.get.ts',
|
||||||
create: 'create.post.ts',
|
create: 'create.post.ts',
|
||||||
show: (by: string) => `${by}.get.ts`,
|
show: (by: string) => `[${by}].get.ts`,
|
||||||
put: (by: string) => `${by}.put.ts`,
|
put: (by: string) => `[${by}].put.ts`,
|
||||||
delete: (by: string) => `${by}.delete.ts`,
|
delete: (by: string) => `[${by}].delete.ts`,
|
||||||
}
|
}
|
||||||
resources.forEach((route: Resource) => {
|
resources.forEach((route: Resource) => {
|
||||||
const fileName = typeof routeTypes[route.type] === 'function'
|
const fileName = typeof routeTypes[route.type] === 'function'
|
||||||
|
|||||||
@ -4,4 +4,5 @@ export interface ModuleOptions {
|
|||||||
uri: string
|
uri: string
|
||||||
devtools: boolean
|
devtools: boolean
|
||||||
options?: ConnectOptions
|
options?: ConnectOptions
|
||||||
|
modelsDir?: string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user