@sfxcode/nuxt-mongocamp-server 1.9.2 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -5
- package/dist/module.d.mts +31 -1
- package/dist/module.json +2 -2
- package/dist/module.mjs +41 -4
- package/dist/runtime/composables/mongocampApi.js +7 -0
- package/dist/runtime/server/composables/mongocampApi.d.ts +2 -1
- package/dist/runtime/server/composables/mongocampApi.js +11 -5
- package/dist/runtime/server/composables/mongocampServerApi.d.ts +2 -1
- package/dist/runtime/server/composables/mongocampServerApi.js +3 -7
- package/dist/runtime/server/mongocamp/core.d.ts +22 -0
- package/dist/runtime/server/mongocamp/core.js +32 -0
- package/dist/runtime/server/mongocamp/handler.d.ts +3 -0
- package/dist/runtime/server/mongocamp/handler.js +8 -0
- package/dist/runtime/server/mongocamp/plugin.d.ts +3 -0
- package/dist/runtime/server/mongocamp/plugin.js +7 -0
- package/dist/types.d.mts +1 -1
- package/package.json +38 -27
package/README.md
CHANGED
|
@@ -4,7 +4,18 @@ Nuxt module wrapping a generated OpenAPI client for [MongoCamp](https://mongocam
|
|
|
4
4
|
|
|
5
5
|
## MongoCamp Server
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The module works in two modes:
|
|
8
|
+
|
|
9
|
+
- **Embedded server** (`server.enabled`): the MongoCamp API runs inside the Nitro of your application (`@sfxcode/mongocamp-server-core`, a TypeScript replacement of the Scala server with the same OpenAPI contract). No second application is needed.
|
|
10
|
+
- **External server**: the module is a client for a running server at `url`.
|
|
11
|
+
|
|
12
|
+
The module runs on **Nitro 3 / h3 2**. Nuxt 4.7 builds with Nitro 3 (`@nuxt/nitro-v3-server`) when the application declares `nitro`:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @sfxcode/nuxt-mongocamp-server nitro
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
In external mode, this module is a client for [MongoCamp Server](https://github.com/MongoCamp/mongocamp-server), a REST API server for MongoDB that provides authentication, user/role management, and collection, document and index APIs. The OpenAPI client in this module is generated from the server's OpenAPI spec, so the module version should match a compatible server version. See the [server repository](https://github.com/MongoCamp/mongocamp-server) for installation, configuration and API documentation.
|
|
8
19
|
|
|
9
20
|
## Nuxt UI MongoCamp
|
|
10
21
|
|
|
@@ -12,10 +23,69 @@ This module is a client for [MongoCamp Server](https://github.com/MongoCamp/mong
|
|
|
12
23
|
|
|
13
24
|
## Setup
|
|
14
25
|
|
|
26
|
+
### Embedded server
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// nuxt.config.ts
|
|
30
|
+
export default defineNuxtConfig({
|
|
31
|
+
modules: ['@sfxcode/nuxt-mongocamp-server'],
|
|
32
|
+
mongocamp: {
|
|
33
|
+
server: {
|
|
34
|
+
enabled: true,
|
|
35
|
+
// prefix: '/api/mongocamp-server', the url of the clients defaults to it
|
|
36
|
+
config: { CONNECTION_DATABASE: 'mongocamp' },
|
|
37
|
+
},
|
|
38
|
+
refreshToken: true,
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The connection and every other setting use the env variables of the Scala server, so existing deployments keep their environment:
|
|
44
|
+
|
|
45
|
+
| Env | Default | Description |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| `CONNECTION_HOST`, `CONNECTION_PORT` | `localhost`, `27017` | MongoDB server (or `NUXT_MONGOCAMP_SERVER_CONNECTION_URI` for a full connection string) |
|
|
48
|
+
| `CONNECTION_DATABASE` | `mongocamp` | default database |
|
|
49
|
+
| `CONNECTION_USERNAME`, `CONNECTION_PASSWORD`, `CONNECTION_AUTHDB` | —, —, `admin` | credentials of the database user |
|
|
50
|
+
| `AUTH_HANDLER` | `mongo` | users and roles in `mc_users` / `mc_roles` (`static`: `AUTH_USERS`, `AUTH_ROLES`) |
|
|
51
|
+
| `AUTH_SECRET` | random, stored | secret of the tokens (stored in `mc_configuration`, shared by all instances) |
|
|
52
|
+
| `AUTH_EXPIRING_DURATION` | `6h` | lifetime of a token |
|
|
53
|
+
| `REQUESTLOGGING_ENABLED`, `METRICS_ENABLED` | `false` | request log and metrics (the former plugins) |
|
|
54
|
+
|
|
55
|
+
At the first start the user `admin` is created with a random password that is printed to the log (like the Scala server). Further settings
|
|
56
|
+
and the extension points (events, job handlers) are described in [`packages/server-core/README.md`](packages/server-core/README.md). In
|
|
57
|
+
server code `useMongocampCore()` gives the embedded server, e.g. to listen to its events:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// server/plugins/audit.ts
|
|
61
|
+
import { definePlugin } from 'nitro'
|
|
62
|
+
|
|
63
|
+
export default definePlugin(async () => {
|
|
64
|
+
const core = await useMongocampCore()
|
|
65
|
+
core.events.on('document:delete', event => console.info(event.user.userId, event.collectionName, event.oldValues))
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Migration from the Scala server** (details and all differences: [`docs/migration-from-scala.md`](docs/migration-from-scala.md)): point the embedded server at the same database (the same `CONNECTION_*` and `AUTH_PREFIX`); users,
|
|
70
|
+
roles, tokens, the token secret and the stored configurations keep working. Jobs are read from `mc_jobs` with cron expressions in the
|
|
71
|
+
syntax of [croner](https://croner.56k.guru) (`*/5` instead of `0/5`); the Quartz tables `mc_jobs_*` are not read.
|
|
72
|
+
|
|
73
|
+
### Standalone server
|
|
74
|
+
|
|
75
|
+
`apps/server` is the same server without Nuxt (Nitro 3), configured only by env and listening on `SERVER_INTERFACE:SERVER_PORT`
|
|
76
|
+
(default `0.0.0.0:8080`) like the Scala image:
|
|
77
|
+
|
|
15
78
|
```bash
|
|
16
|
-
|
|
79
|
+
docker build -f apps/server/Dockerfile -t mongocamp-nitro-server .
|
|
80
|
+
docker run -p 8080:8080 -e CONNECTION_HOST=host.docker.internal mongocamp-nitro-server
|
|
17
81
|
```
|
|
18
82
|
|
|
83
|
+
The image (distroless Node 24, about 214 MB, the server itself 2.8 MB) stops cleanly on `docker stop` (SIGTERM) and on `DELETE /system`.
|
|
84
|
+
|
|
85
|
+
The spec is served at `/docs/docs.yaml` (`DOCS_OPENAPI`, default on) and an API reference UI at `/docs` (`DOCS_SWAGGER`).
|
|
86
|
+
|
|
87
|
+
### External server
|
|
88
|
+
|
|
19
89
|
```ts
|
|
20
90
|
// nuxt.config.ts
|
|
21
91
|
export default defineNuxtConfig({
|
|
@@ -33,7 +103,12 @@ export default defineNuxtConfig({
|
|
|
33
103
|
|
|
34
104
|
| Option | Type | Default | Description |
|
|
35
105
|
| ------------------------| --------- | ------- | ----------------------------------------------------------------------------------------------|
|
|
36
|
-
| `url` | `string` | — |
|
|
106
|
+
| `url` | `string` | — | Base URL of the MongoCamp server. Required without the embedded server, which it defaults to. |
|
|
107
|
+
| `server.enabled` | `boolean` | `false` | Runs the MongoCamp API inside this application. |
|
|
108
|
+
| `server.prefix` | `string` | `/api/mongocamp-server` | Path of the embedded API. |
|
|
109
|
+
| `server.connectionUri` | `string` | — | MongoDB connection string; better by env `NUXT_MONGOCAMP_SERVER_CONNECTION_URI`. |
|
|
110
|
+
| `server.config` | `object` | `{}` | Settings by key (`CONNECTION_DATABASE`, ...); the env variables win. |
|
|
111
|
+
| `server.jobs` | `boolean` | `true` | Runs the jobs (token cleanup, ...) on their schedule in this instance. |
|
|
37
112
|
| `apiKey` | `string` | — | Optional. Stored server-side only; picked up automatically by `useMongocampApi(event)`. |
|
|
38
113
|
| `paginationSize` | `number` | `500` | Default rows per page for search/list composables. Values below 10 fall back to the default. |
|
|
39
114
|
| `refreshToken` | `boolean` | `false` | Whether the client auto-refreshes the session token on an interval after login. |
|
|
@@ -63,12 +138,15 @@ A missing `url` throws during `nuxi dev`/`nuxi build`/`nuxi generate` (not durin
|
|
|
63
138
|
|
|
64
139
|
| Composable | Purpose |
|
|
65
140
|
| -----------------------------------------------| -----------------------------------------------------------------------------------|
|
|
66
|
-
| `useMongocampApi(event, token?)` | Builds authenticated API clients using the module's `apiKey`, or the given `token` as a fallback. |
|
|
141
|
+
| `useMongocampApi(event, token?)` | Builds authenticated API clients using the module's `apiKey`, or the given `token` as a fallback. With the embedded server the calls are answered in-process. |
|
|
142
|
+
| `useMongocampCore()` | The embedded server (`server.enabled` only): events, configuration, direct access. |
|
|
67
143
|
| `useMongocampServerApi(url, key?, token?)` | Lower-level factory when you need to authenticate against a different URL/credential explicitly. |
|
|
68
144
|
|
|
69
145
|
```ts
|
|
70
146
|
// server/api/mongocamp/users.ts
|
|
71
|
-
|
|
147
|
+
import { defineHandler } from 'nitro'
|
|
148
|
+
|
|
149
|
+
export default defineHandler((event) => {
|
|
72
150
|
const { adminApi } = useMongocampApi(event)
|
|
73
151
|
return adminApi.listUsers()
|
|
74
152
|
})
|
package/dist/module.d.mts
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
export * from '../dist/runtime/api/index.js';
|
|
3
3
|
|
|
4
|
+
/** The option `server` of the module: the MongoCamp server embedded in the Nitro of the application. */
|
|
5
|
+
interface ServerOptions {
|
|
6
|
+
/** Serves the MongoCamp API from this application (default false: an external server at `url`). */
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
/** The path of the API (default `/api/mongocamp-server`). */
|
|
9
|
+
prefix?: string;
|
|
10
|
+
/** A MongoDB connection string; without it the `CONNECTION_*` configurations (env) are used. Better set by env (`NUXT_MONGOCAMP_SERVER_CONNECTION_URI`). */
|
|
11
|
+
connectionUri?: string;
|
|
12
|
+
/** Configuration values by key (`CONNECTION_DATABASE`, `AUTH_SECRET`, ...); the env variables of the Scala server win. */
|
|
13
|
+
config?: Record<string, unknown>;
|
|
14
|
+
/** Runs the jobs (token cleanup, ...) on their schedule in this instance (default true). */
|
|
15
|
+
jobs?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface ResolvedServerOptions {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
prefix: string;
|
|
20
|
+
connectionUri: string;
|
|
21
|
+
config: Record<string, unknown>;
|
|
22
|
+
jobs: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
4
25
|
interface ModuleOptions {
|
|
26
|
+
/** The url of the MongoCamp API; with `server.enabled` it defaults to the prefix of the embedded server. */
|
|
5
27
|
url: string;
|
|
6
28
|
apiKey?: string;
|
|
7
29
|
paginationSize?: number;
|
|
8
30
|
refreshToken?: boolean;
|
|
9
31
|
tokenRefreshInterval: number;
|
|
10
32
|
sessionMaxAge?: number;
|
|
33
|
+
/** The MongoCamp server embedded in the Nitro of this application. */
|
|
34
|
+
server?: ServerOptions;
|
|
11
35
|
}
|
|
12
36
|
declare module '@nuxt/schema' {
|
|
13
37
|
interface PublicRuntimeConfig {
|
|
@@ -21,9 +45,15 @@ declare module '@nuxt/schema' {
|
|
|
21
45
|
}
|
|
22
46
|
interface RuntimeConfig {
|
|
23
47
|
mongocampApiKey: string;
|
|
48
|
+
mongocampServer: ResolvedServerOptions & {
|
|
49
|
+
version: {
|
|
50
|
+
name: string;
|
|
51
|
+
version: string;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
24
54
|
}
|
|
25
55
|
}
|
|
26
56
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
27
57
|
|
|
28
58
|
export { _default as default };
|
|
29
|
-
export type { ModuleOptions };
|
|
59
|
+
export type { ModuleOptions, ServerOptions };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addImportsDir, addServerImportsDir } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, addImportsDir, addServerImportsDir, addServerHandler, addServerPlugin, addServerImports } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
import { consola } from 'consola';
|
|
4
4
|
export * from '../dist/runtime/api/index.js';
|
|
5
5
|
|
|
6
6
|
const name = "@sfxcode/nuxt-mongocamp-server";
|
|
7
|
-
const version = "1.
|
|
7
|
+
const version = "1.10.0";
|
|
8
|
+
|
|
9
|
+
const DefaultServerPrefix = "/api/mongocamp-server";
|
|
10
|
+
function normalizePrefix(prefix) {
|
|
11
|
+
const trimmed = (prefix ?? DefaultServerPrefix).trim().replace(/\/+$/, "");
|
|
12
|
+
const path = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
13
|
+
if (path === "/" || path === "") {
|
|
14
|
+
throw new Error('[mongocamp] "server.prefix" must not be the root path');
|
|
15
|
+
}
|
|
16
|
+
return path;
|
|
17
|
+
}
|
|
18
|
+
function resolveServerOptions(options) {
|
|
19
|
+
return {
|
|
20
|
+
enabled: options?.enabled ?? false,
|
|
21
|
+
prefix: normalizePrefix(options?.prefix),
|
|
22
|
+
connectionUri: options?.connectionUri ?? "",
|
|
23
|
+
config: options?.config ?? {},
|
|
24
|
+
jobs: options?.jobs ?? true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function resolveClientUrl(url, server) {
|
|
28
|
+
if (url && url.length > 0) {
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
return server.enabled ? server.prefix : void 0;
|
|
32
|
+
}
|
|
8
33
|
|
|
9
34
|
const module$1 = defineNuxtModule({
|
|
10
35
|
meta: {
|
|
@@ -12,15 +37,20 @@ const module$1 = defineNuxtModule({
|
|
|
12
37
|
version,
|
|
13
38
|
configKey: "mongocamp",
|
|
14
39
|
compatibility: {
|
|
15
|
-
nuxt: ">=
|
|
40
|
+
nuxt: ">=4.7.0"
|
|
16
41
|
}
|
|
17
42
|
},
|
|
18
43
|
setup(options, nuxt) {
|
|
44
|
+
if (nuxt.options._nitroMajor !== 3) {
|
|
45
|
+
throw new Error('[mongocamp] the module needs Nitro 3: add "nitro" to the dependencies of the application (Nuxt then builds with @nuxt/nitro-v3-server)');
|
|
46
|
+
}
|
|
47
|
+
const server = resolveServerOptions(options.server);
|
|
48
|
+
options.url = resolveClientUrl(options.url, server) ?? options.url;
|
|
19
49
|
nuxt.hook("ready", () => {
|
|
20
50
|
if (nuxt.options._prepare)
|
|
21
51
|
return;
|
|
22
52
|
if (!options.url || options.url.length === 0)
|
|
23
|
-
throw new Error('[mongocamp] Missing required "url" module option.');
|
|
53
|
+
throw new Error('[mongocamp] Missing required "url" module option (or enable the embedded server with "server.enabled").');
|
|
24
54
|
});
|
|
25
55
|
if (options.paginationSize !== void 0 && options.paginationSize < 10)
|
|
26
56
|
consola.warn(`[mongocamp] paginationSize of ${options.paginationSize} is below the minimum of 10, falling back to 500`);
|
|
@@ -51,6 +81,13 @@ const module$1 = defineNuxtModule({
|
|
|
51
81
|
const runtimeDir = resolve("./runtime");
|
|
52
82
|
addImportsDir(resolve(runtimeDir, "composables"));
|
|
53
83
|
addServerImportsDir(resolve(runtimeDir, "server/composables"));
|
|
84
|
+
nuxt.options.runtimeConfig.mongocampServer = defu(nuxt.options.runtimeConfig.mongocampServer, { ...server, version: { name: "mongocamp-nitro-server", version } });
|
|
85
|
+
if (server.enabled) {
|
|
86
|
+
addServerHandler({ route: `${server.prefix}/**`, handler: resolve(runtimeDir, "server/mongocamp/handler") });
|
|
87
|
+
addServerPlugin(resolve(runtimeDir, "server/mongocamp/plugin"));
|
|
88
|
+
addServerImports([{ name: "useMongocampCore", from: resolve(runtimeDir, "server/mongocamp/core") }]);
|
|
89
|
+
consola.info(`[mongocamp] embedded server at ${server.prefix}`);
|
|
90
|
+
}
|
|
54
91
|
consola.success("mongocamp-nuxt available");
|
|
55
92
|
}
|
|
56
93
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useRequestFetch } from "#app";
|
|
1
2
|
import { Configuration } from "../api/index.js";
|
|
2
3
|
import { createMongocampApis } from "../utils/createMongocampApis.js";
|
|
3
4
|
import { useMongocampUrl } from "./mongocampUrl.js";
|
|
@@ -5,8 +6,14 @@ import { useMongocampStorage } from "./mongocampStorage.js";
|
|
|
5
6
|
export function useMongocampApi() {
|
|
6
7
|
const url = useMongocampUrl();
|
|
7
8
|
const state = useMongocampStorage();
|
|
9
|
+
let fetchApi;
|
|
10
|
+
if (import.meta.server && url?.startsWith("/")) {
|
|
11
|
+
const requestFetch = useRequestFetch();
|
|
12
|
+
fetchApi = ((input, init) => requestFetch.native(input, init));
|
|
13
|
+
}
|
|
8
14
|
const configuration = new Configuration({
|
|
9
15
|
basePath: url,
|
|
16
|
+
...fetchApi ? { fetchApi } : {},
|
|
10
17
|
accessToken: () => state.value.token,
|
|
11
18
|
middleware: [{
|
|
12
19
|
// a 401 means the token itself is invalid/expired, so clear it everywhere.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { H3Event } from 'h3';
|
|
2
|
-
|
|
2
|
+
/** The generated client for the server code; `event` is kept for the signature of the earlier versions. */
|
|
3
|
+
export declare function useMongocampApi(_event: H3Event, token?: string): {
|
|
3
4
|
adminApi: import("../../api/index.js").AdminApi;
|
|
4
5
|
applicationApi: import("../../api/index.js").ApplicationApi;
|
|
5
6
|
authApi: import("../../api/index.js").AuthApi;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "
|
|
1
|
+
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
2
|
+
import { useMongocampCore } from "../mongocamp/core.js";
|
|
2
3
|
import { useMongocampServerApi } from "./mongocampServerApi.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
4
|
+
const EmbeddedBase = "http://mongocamp.embedded";
|
|
5
|
+
export function useMongocampApi(_event, token) {
|
|
6
|
+
const config = useRuntimeConfig();
|
|
6
7
|
const apiKey = config.mongocampApiKey;
|
|
7
|
-
|
|
8
|
+
const embedded = config.mongocampServer;
|
|
9
|
+
if (embedded?.enabled) {
|
|
10
|
+
const fetchApi = async (input, init) => (await useMongocampCore(embedded)).fetch(new Request(input, init));
|
|
11
|
+
return useMongocampServerApi(EmbeddedBase, apiKey, token, fetchApi);
|
|
12
|
+
}
|
|
13
|
+
return useMongocampServerApi(config.public.mongocamp?.url, apiKey, token);
|
|
8
14
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { FetchAPI } from '../../api/index.js';
|
|
2
|
+
export declare function useMongocampServerApi(url: string, key?: string, token?: string, fetchApi?: FetchAPI): {
|
|
2
3
|
adminApi: import("../../api/index.js").AdminApi;
|
|
3
4
|
applicationApi: import("../../api/index.js").ApplicationApi;
|
|
4
5
|
authApi: import("../../api/index.js").AuthApi;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { Configuration } from "../../api/index.js";
|
|
2
2
|
import { createMongocampApis } from "../../utils/createMongocampApis.js";
|
|
3
|
-
export function useMongocampServerApi(url, key, token) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
configuration = new Configuration({ basePath: url, apiKey: key });
|
|
7
|
-
else if (token && token.length > 0)
|
|
8
|
-
configuration = new Configuration({ basePath: url, accessToken: token });
|
|
9
|
-
return createMongocampApis(configuration);
|
|
3
|
+
export function useMongocampServerApi(url, key, token, fetchApi) {
|
|
4
|
+
const credentials = key && key.length > 0 ? { apiKey: key } : token && token.length > 0 ? { accessToken: token } : {};
|
|
5
|
+
return createMongocampApis(new Configuration({ basePath: url, ...credentials, ...fetchApi ? { fetchApi } : {} }));
|
|
10
6
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MongocampServer } from '@sfxcode/mongocamp-server-core';
|
|
2
|
+
/** The settings of the embedded server in the private runtime config (`runtimeConfig.mongocampServer`). */
|
|
3
|
+
export interface EmbeddedServerConfig {
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
prefix: string;
|
|
6
|
+
connectionUri: string;
|
|
7
|
+
config: Record<string, unknown>;
|
|
8
|
+
jobs: boolean;
|
|
9
|
+
version: {
|
|
10
|
+
name: string;
|
|
11
|
+
version: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The MongoCamp server of this Nitro instance, created with the first request. The env variables of the Scala server (`CONNECTION_*`,
|
|
16
|
+
* `AUTH_*`, ...) are read by the core and win over `config`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useMongocampCore(settings?: EmbeddedServerConfig): Promise<MongocampServer>;
|
|
19
|
+
/** Closes the server (database, scheduler, timers) when Nitro stops. */
|
|
20
|
+
export declare function closeMongocampCore(): Promise<void>;
|
|
21
|
+
/** A request for the core: the path without the prefix, the body as a stream. */
|
|
22
|
+
export declare function toCoreRequest(request: Request, prefix: string): Request;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createMongocampServer } from "@sfxcode/mongocamp-server-core";
|
|
2
|
+
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
3
|
+
let server;
|
|
4
|
+
export function useMongocampCore(settings = useRuntimeConfig().mongocampServer) {
|
|
5
|
+
if (!settings.enabled) {
|
|
6
|
+
return Promise.reject(new Error('[mongocamp] the embedded server is not enabled (module option "server.enabled")'));
|
|
7
|
+
}
|
|
8
|
+
server ??= createMongocampServer({
|
|
9
|
+
connectionUri: settings.connectionUri || void 0,
|
|
10
|
+
config: settings.config,
|
|
11
|
+
jobs: settings.jobs,
|
|
12
|
+
version: settings.version
|
|
13
|
+
}).catch((error) => {
|
|
14
|
+
server = void 0;
|
|
15
|
+
throw error;
|
|
16
|
+
});
|
|
17
|
+
return server;
|
|
18
|
+
}
|
|
19
|
+
export async function closeMongocampCore() {
|
|
20
|
+
const current = server;
|
|
21
|
+
server = void 0;
|
|
22
|
+
if (current) {
|
|
23
|
+
await (await current.catch(() => void 0))?.close();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function toCoreRequest(request, prefix) {
|
|
27
|
+
const url = new URL(request.url);
|
|
28
|
+
url.pathname = url.pathname.startsWith(prefix) ? url.pathname.slice(prefix.length) || "/" : url.pathname;
|
|
29
|
+
const headers = new Headers(request.headers);
|
|
30
|
+
headers.set("x-forwarded-prefix", prefix);
|
|
31
|
+
return new Request(url, { method: request.method, headers, body: request.body, duplex: "half", signal: request.signal });
|
|
32
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { defineHandler } from "nitro";
|
|
2
|
+
import { useRuntimeConfig } from "nitro/runtime-config";
|
|
3
|
+
import { toCoreRequest, useMongocampCore } from "./core.js";
|
|
4
|
+
export default defineHandler(async (event) => {
|
|
5
|
+
const settings = useRuntimeConfig().mongocampServer;
|
|
6
|
+
const core = await useMongocampCore(settings);
|
|
7
|
+
return core.fetch(toCoreRequest(event.req, settings.prefix));
|
|
8
|
+
});
|
package/dist/types.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sfxcode/nuxt-mongocamp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -27,40 +27,51 @@
|
|
|
27
27
|
"build": {
|
|
28
28
|
"failOnWarn": false
|
|
29
29
|
},
|
|
30
|
-
"scripts": {
|
|
31
|
-
"prepack": "nuxt-module-build build",
|
|
32
|
-
"dev": "nuxi dev playground",
|
|
33
|
-
"dev:build": "nuxi build playground",
|
|
34
|
-
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
35
|
-
"release": "npm run lint && npm run test && npm run prepack && changelogen --patch --release && npm publish --access public && git push --follow-tags",
|
|
36
|
-
"lint": "eslint .",
|
|
37
|
-
"lint:fix": "eslint --fix .",
|
|
38
|
-
"test": "vitest run",
|
|
39
|
-
"test:watch": "vitest watch",
|
|
40
|
-
"test:coverage": "vitest run --coverage",
|
|
41
|
-
"test:update": "vitest run --update",
|
|
42
|
-
"test:update:watch": "vitest run --update --watch",
|
|
43
|
-
"api-codegen": "openapi-generator-cli generate -i ./openapi/docs.yaml -g typescript-fetch -o src/runtime/api --additional-properties=typescriptThreePlus=true,supportsES6=true"
|
|
44
|
-
},
|
|
45
30
|
"dependencies": {
|
|
46
|
-
"@nuxt/kit": "^4.
|
|
47
|
-
"@
|
|
31
|
+
"@nuxt/kit": "^4.7.0",
|
|
32
|
+
"@sfxcode/mongocamp-server-core": "1.10.0",
|
|
33
|
+
"@vueuse/nuxt": "^15.1.0",
|
|
48
34
|
"consola": "^3.4.2",
|
|
49
35
|
"defu": "^6.1.7"
|
|
50
36
|
},
|
|
51
37
|
"devDependencies": {
|
|
52
|
-
"@nuxt/devtools": "^4.2.
|
|
38
|
+
"@nuxt/devtools": "^4.2.2",
|
|
53
39
|
"@nuxt/eslint-config": "^1.17.0",
|
|
54
40
|
"@nuxt/module-builder": "^1.0.4",
|
|
55
|
-
"@nuxt/schema": "^4.
|
|
41
|
+
"@nuxt/schema": "^4.7.0",
|
|
56
42
|
"@nuxt/test-utils": "^4.4.0",
|
|
57
|
-
"@openapitools/openapi-generator-cli": "^2.
|
|
58
|
-
"@types/node": "^26.6.
|
|
43
|
+
"@openapitools/openapi-generator-cli": "^2.44.0",
|
|
44
|
+
"@types/node": "^26.6.11",
|
|
59
45
|
"@unocss/nuxt": "^66.13.0",
|
|
60
46
|
"changelogen": "^0.6.2",
|
|
61
|
-
"eslint": "^10.
|
|
62
|
-
"
|
|
63
|
-
"
|
|
47
|
+
"eslint": "^10.16.0",
|
|
48
|
+
"h3": "2.0.8",
|
|
49
|
+
"mongodb": "7.9.1",
|
|
50
|
+
"nitro": "3.0.261103-rc",
|
|
51
|
+
"nuxt": "^4.7.0",
|
|
52
|
+
"srvx": "1.0.8",
|
|
53
|
+
"typescript": "6.0.3",
|
|
54
|
+
"vitest": "^5.1.2"
|
|
64
55
|
},
|
|
65
|
-
"
|
|
66
|
-
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"nitro": ">=3.0.261103-rc",
|
|
58
|
+
"nuxt": ">=4.7.0"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"dev": "nuxi dev playground",
|
|
62
|
+
"dev:build": "nuxi build playground",
|
|
63
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
64
|
+
"release": "npm run lint && npm run test && npm run prepack && changelogen --minor --release --no-commit --no-tag && node scripts/sync-versions.mjs --commit && pnpm -r --include-workspace-root --filter @sfxcode/mongocamp-server-core --filter @sfxcode/nuxt-mongocamp-server publish --access public && git push --follow-tags",
|
|
65
|
+
"lint": "eslint .",
|
|
66
|
+
"lint:fix": "eslint --fix .",
|
|
67
|
+
"test": "vitest run",
|
|
68
|
+
"test:watch": "vitest watch",
|
|
69
|
+
"test:coverage": "vitest run --coverage",
|
|
70
|
+
"test:update": "vitest run --update",
|
|
71
|
+
"test:update:watch": "vitest run --update --watch",
|
|
72
|
+
"api-codegen": "openapi-generator-cli generate -i ./openapi/docs.yaml -g typescript-fetch -o src/runtime/api --additional-properties=typescriptThreePlus=true,supportsES6=true",
|
|
73
|
+
"test:contract": "vitest run --config vitest.contract.config.ts",
|
|
74
|
+
"typecheck:server": "pnpm --filter @sfxcode/mongocamp-server-core typecheck",
|
|
75
|
+
"sync-versions": "node scripts/sync-versions.mjs"
|
|
76
|
+
}
|
|
77
|
+
}
|