@miso.ai/doggoganger 0.9.0 → 0.9.1-beta.2

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/cli/index.js CHANGED
@@ -4,7 +4,7 @@ import { dirname, resolve, join } from 'path';
4
4
  import nodemon from 'nodemon';
5
5
  import yargs from 'yargs/yargs';
6
6
  import { hideBin } from 'yargs/helpers';
7
- import doggoganger from '../src/index.js';
7
+ import { doggoganger } from '../src/index.js';
8
8
 
9
9
  const __dirname = dirname(fileURLToPath(import.meta.url));
10
10
  const SRC_DIR = join(__dirname, '../src');
package/cli/server.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import doggoganger from '../src/index.js';
2
+ import { doggoganger } from '../src/index.js';
3
3
 
4
4
  doggoganger(JSON.parse(process.argv[2]));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miso.ai/doggoganger",
3
- "version": "0.9.0",
3
+ "version": "0.9.1-beta.2",
4
4
  "description": "A dummy miso endpoint for demo and testing",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,54 @@
1
+ import Koa from 'koa';
2
+ import Router from '@koa/router';
3
+ import cors from '@koa/cors';
4
+ import serveStatic from 'koa-static';
5
+ import { koaBody } from 'koa-body';
6
+ import _route from './route/index.js';
7
+ import Api from './api/index.js';
8
+ import { exclusion } from './utils.js';
9
+
10
+ export default function doggoganger({ port = 9901, serve = false, ...options } = {}) {
11
+ const app = new Koa();
12
+ const router = new Router();
13
+ const api = _route(new Api(options), options);
14
+
15
+ router.use('/api', api.routes(), api.allowedMethods());
16
+ router.use('/v1', api.routes(), api.allowedMethods());
17
+
18
+ if (serve) {
19
+ app
20
+ .use(exclusion)
21
+ .use(serveStatic('.'));
22
+ }
23
+
24
+ app
25
+ .use(cors())
26
+ .use(koaBody({
27
+ formLimit: '100mb',
28
+ textLimit: '100mb',
29
+ jsonLimit: '100mb',
30
+ onerror: function (err, ctx) {
31
+ console.error(err);
32
+ ctx.throw('body parse error', 422);
33
+ },
34
+ }))
35
+ .use(handleAllPath(options))
36
+ .use(router.routes())
37
+ .use(router.allowedMethods())
38
+ .use(handleUnrecognizedPath(options))
39
+ .listen(port);
40
+ }
41
+
42
+ function handleAllPath({ verbose } = {}) {
43
+ return async (ctx, next) => {
44
+ verbose && console.log(`${ctx.method} ${ctx.url}`);
45
+ await next();
46
+ };
47
+ }
48
+
49
+ function handleUnrecognizedPath({ verbose } = {}) {
50
+ return async (ctx, next) => {
51
+ verbose && console.log(`Unrecognized path: ${ctx.method} ${ctx.url}`);
52
+ await next();
53
+ };
54
+ }
package/src/index.js CHANGED
@@ -1,54 +1,6 @@
1
- import Koa from 'koa';
2
- import Router from '@koa/router';
3
- import cors from '@koa/cors';
4
- import serveStatic from 'koa-static';
5
- import { koaBody } from 'koa-body';
6
- import _route from './route/index.js';
1
+ export { default as doggoganger } from './doggoganger.js';
7
2
  import Api from './api/index.js';
8
- import { exclusion } from './utils.js';
9
3
 
10
- export default function doggoganger({ port = 9901, serve = false, ...options } = {}) {
11
- const app = new Koa();
12
- const router = new Router();
13
- const api = _route(new Api(options), options);
14
-
15
- router.use('/api', api.routes(), api.allowedMethods());
16
- router.use('/v1', api.routes(), api.allowedMethods());
17
-
18
- if (serve) {
19
- app
20
- .use(exclusion)
21
- .use(serveStatic('.'));
22
- }
23
-
24
- app
25
- .use(cors())
26
- .use(koaBody({
27
- formLimit: '100mb',
28
- textLimit: '100mb',
29
- jsonLimit: '100mb',
30
- onerror: function (err, ctx) {
31
- console.error(err);
32
- ctx.throw('body parse error', 422);
33
- },
34
- }))
35
- .use(handleAllPath(options))
36
- .use(router.routes())
37
- .use(router.allowedMethods())
38
- .use(handleUnrecognizedPath(options))
39
- .listen(port);
40
- }
41
-
42
- function handleAllPath({ verbose } = {}) {
43
- return async (ctx, next) => {
44
- verbose && console.log(`${ctx.method} ${ctx.url}`);
45
- await next();
46
- };
47
- }
48
-
49
- function handleUnrecognizedPath({ verbose } = {}) {
50
- return async (ctx, next) => {
51
- verbose && console.log(`Unrecognized path: ${ctx.method} ${ctx.url}`);
52
- await next();
53
- };
54
- }
4
+ export function buildApi(...args) {
5
+ return new Api(...args);
6
+ };