@gasket/plugin-fastify 7.5.2 → 8.0.0-next.1
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/lib/create-servers.js +9 -18
- package/lib/index.js +0 -2
- package/package.json +8 -12
- package/cjs/actions.cjs +0 -21
- package/cjs/create-servers.cjs +0 -41
- package/cjs/create.cjs +0 -72
- package/cjs/index.cjs +0 -84
- package/cjs/package.json +0 -1
- package/cjs/utils.cjs +0 -66
- package/generator/app/plugins/README.md +0 -11
- package/generator/app/plugins/routes-plugin.js +0 -30
- package/generator/app/plugins/routes-plugin.ts +0 -29
- package/generator/jest/jest.config.js +0 -21
- package/generator/jest/test/index.test.js +0 -20
- package/generator/jest/test/index.test.ts +0 -26
- package/generator/mocha/test/index.test.js +0 -23
- package/generator/mocha/test/index.test.ts +0 -23
- package/generator/vitest/test/index.test.js +0 -21
- package/generator/vitest/test/index.test.ts +0 -21
- package/lib/create.js +0 -61
package/lib/create-servers.js
CHANGED
|
@@ -5,32 +5,23 @@ import { getAppInstance } from './utils.js';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Create the Fastify instance and setup the lifecycle hooks.
|
|
8
|
-
* Fastify is compatible with express middleware
|
|
8
|
+
* Fastify is compatible with express middleware out of the box, so we can
|
|
9
|
+
* use the same middleware lifecycles.
|
|
9
10
|
* @type {import('@gasket/core').HookHandler<'createServers'>}
|
|
10
11
|
*/
|
|
11
12
|
export default async function createServers(gasket, serverOpts) {
|
|
12
|
-
|
|
13
|
+
/** Cast to Fastify + Express hybrid because Gasket adds `.use()` via @fastify/express plugin */
|
|
14
|
+
const app = /** @type {import('fastify').FastifyInstance & { use: Function }} */ (getAppInstance(gasket));
|
|
13
15
|
|
|
14
16
|
// allow consuming apps to directly append options to their server
|
|
15
17
|
await gasket.exec('fastify', app);
|
|
16
18
|
|
|
17
19
|
const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
'errorMiddleware requires @fastify/express to be installed and registered. ' +
|
|
24
|
-
'Install @fastify/express and ensure @gasket/plugin-middleware is configured.'
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
postRenderingStacks.forEach((stack) => {
|
|
28
|
-
/** @type {import('connect').NextHandleFunction} */
|
|
29
|
-
const middleware = stack;
|
|
30
|
-
// @ts-expect-error
|
|
31
|
-
app.use(middleware);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
20
|
+
postRenderingStacks.forEach((stack) => {
|
|
21
|
+
/** @type {import('connect').NextHandleFunction} */
|
|
22
|
+
const middleware = stack;
|
|
23
|
+
app.use(middleware);
|
|
24
|
+
});
|
|
34
25
|
|
|
35
26
|
return {
|
|
36
27
|
...serverOpts,
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="@gasket/core" />
|
|
2
2
|
/// <reference types="@gasket/plugin-metadata" />
|
|
3
3
|
|
|
4
|
-
import create from './create.js';
|
|
5
4
|
import createServers from './create-servers.js';
|
|
6
5
|
import actions from './actions.js';
|
|
7
6
|
import packageJson from '../package.json' with { type: 'json' };
|
|
@@ -14,7 +13,6 @@ const plugin = {
|
|
|
14
13
|
description,
|
|
15
14
|
actions,
|
|
16
15
|
hooks: {
|
|
17
|
-
create,
|
|
18
16
|
createServers,
|
|
19
17
|
metadata(gasket, meta) {
|
|
20
18
|
return {
|
package/package.json
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-fastify",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-next.1",
|
|
4
4
|
"description": "Adds fastify support to your application",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./lib/index.js",
|
|
7
6
|
"types": "./lib/index.d.ts",
|
|
8
7
|
"files": [
|
|
9
|
-
"cjs",
|
|
10
8
|
"generator",
|
|
11
9
|
"lib",
|
|
12
10
|
"EXAMPLES.md"
|
|
@@ -14,8 +12,7 @@
|
|
|
14
12
|
"exports": {
|
|
15
13
|
".": {
|
|
16
14
|
"types": "./lib/index.d.ts",
|
|
17
|
-
"import": "./lib/index.js"
|
|
18
|
-
"require": "./cjs/index.cjs"
|
|
15
|
+
"import": "./lib/index.js"
|
|
19
16
|
},
|
|
20
17
|
"./package.json": "./package.json"
|
|
21
18
|
},
|
|
@@ -33,24 +30,23 @@
|
|
|
33
30
|
"bugs": "https://github.com/godaddy/gasket/issues",
|
|
34
31
|
"homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-plugin-fastify",
|
|
35
32
|
"dependencies": {
|
|
33
|
+
"@fastify/express": "^3.0.0",
|
|
36
34
|
"fastify": "^4.29.1"
|
|
37
35
|
},
|
|
38
36
|
"devDependencies": {
|
|
39
37
|
"@types/connect": "^3.4.38",
|
|
40
38
|
"fastify": "^4.29.1",
|
|
41
39
|
"vitest": "^3.2.0",
|
|
42
|
-
"@gasket/core": "^
|
|
43
|
-
"@gasket/plugin-https": "^
|
|
44
|
-
"@gasket/plugin-logger": "^
|
|
45
|
-
"@gasket/plugin-metadata": "^
|
|
46
|
-
"create-gasket-app": "^
|
|
47
|
-
"@gasket/cjs": "^7.1.1"
|
|
40
|
+
"@gasket/core": "^8.0.0-next.1",
|
|
41
|
+
"@gasket/plugin-https": "^8.0.0-next.1",
|
|
42
|
+
"@gasket/plugin-logger": "^8.0.0-next.1",
|
|
43
|
+
"@gasket/plugin-metadata": "^8.0.0-next.1",
|
|
44
|
+
"create-gasket-app": "^8.0.0-next.1"
|
|
48
45
|
},
|
|
49
46
|
"peerDependencies": {
|
|
50
47
|
"fastify": "^4.29.1"
|
|
51
48
|
},
|
|
52
49
|
"scripts": {
|
|
53
|
-
"build": "gasket-cjs ./lib",
|
|
54
50
|
"lint": "eslint .",
|
|
55
51
|
"lint:fix": "pnpm run lint --fix",
|
|
56
52
|
"posttest": "pnpm run lint && pnpm run typecheck",
|
package/cjs/actions.cjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", {
|
|
2
|
-
value: true
|
|
3
|
-
});
|
|
4
|
-
Object.defineProperty(exports, "default", {
|
|
5
|
-
enumerable: true,
|
|
6
|
-
get: function() {
|
|
7
|
-
return _default;
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
const _utils = require("./utils.cjs");
|
|
11
|
-
const actions = {
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated
|
|
14
|
-
* @param {import('@gasket/core').Gasket} gasket - Gasket instance
|
|
15
|
-
* @returns {import('fastify').FastifyInstance} - Fastify instance
|
|
16
|
-
*/ getFastifyApp (gasket) {
|
|
17
|
-
gasket.logger.warn(`DEPRECATED \`getFastifyApp\` action will not be support in future major release.`);
|
|
18
|
-
return (0, _utils.getAppInstance)(gasket);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const _default = actions;
|
package/cjs/create-servers.cjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/// <reference types="@gasket/plugin-https" />
|
|
2
|
-
/// <reference types="@gasket/plugin-logger" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, /**
|
|
7
|
-
* Create the Fastify instance and setup the lifecycle hooks.
|
|
8
|
-
* Fastify is compatible with express middleware when @fastify/express is installed.
|
|
9
|
-
* @type {import('@gasket/core').HookHandler<'createServers'>}
|
|
10
|
-
*/ "default", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function() {
|
|
13
|
-
return createServers;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
const _utils = require("./utils.cjs");
|
|
17
|
-
async function createServers(gasket, serverOpts) {
|
|
18
|
-
const app = (0, _utils.getAppInstance)(gasket);
|
|
19
|
-
// allow consuming apps to directly append options to their server
|
|
20
|
-
await gasket.exec('fastify', app);
|
|
21
|
-
const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
|
|
22
|
-
if (postRenderingStacks.length > 0) {
|
|
23
|
-
// app.use() is added by @fastify/express when registered via @gasket/plugin-middleware
|
|
24
|
-
// @ts-expect-error
|
|
25
|
-
if (typeof app.use !== 'function') {
|
|
26
|
-
throw new Error('errorMiddleware requires @fastify/express to be installed and registered. ' + 'Install @fastify/express and ensure @gasket/plugin-middleware is configured.');
|
|
27
|
-
}
|
|
28
|
-
postRenderingStacks.forEach((stack)=>{
|
|
29
|
-
/** @type {import('connect').NextHandleFunction} */ const middleware = stack;
|
|
30
|
-
// @ts-expect-error
|
|
31
|
-
app.use(middleware);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
...serverOpts,
|
|
36
|
-
handler: async function handler(...args) {
|
|
37
|
-
await app.ready();
|
|
38
|
-
app.server.emit('request', ...args);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
package/cjs/create.cjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/// <reference types="@gasket/core" />
|
|
2
|
-
/// <reference types="create-gasket-app" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, /**
|
|
7
|
-
* Add files & extend package.json for new apps.
|
|
8
|
-
* @type {import('@gasket/core').HookHandler<'create'>}
|
|
9
|
-
*/ "default", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function() {
|
|
12
|
-
return create;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
const _url = require("url");
|
|
16
|
-
const _path = require("path");
|
|
17
|
-
const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
|
|
18
|
-
function _interop_require_default(obj) {
|
|
19
|
-
return obj && obj.__esModule ? obj : {
|
|
20
|
-
default: obj
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
const __filename1 = (0, _url.fileURLToPath)(require("url").pathToFileURL(__filename).toString());
|
|
24
|
-
const __dirname = (0, _path.dirname)(__filename1);
|
|
25
|
-
const { name, version, devDependencies } = _packagejson.default;
|
|
26
|
-
const createTestFiles = ({ files, generatorDir, testPlugins, globIgnore })=>{
|
|
27
|
-
if (!testPlugins || testPlugins.length === 0) return;
|
|
28
|
-
const unit = [
|
|
29
|
-
'jest',
|
|
30
|
-
'mocha',
|
|
31
|
-
'vitest'
|
|
32
|
-
];
|
|
33
|
-
const integration = [
|
|
34
|
-
'cypress'
|
|
35
|
-
];
|
|
36
|
-
const frameworks = [
|
|
37
|
-
...unit,
|
|
38
|
-
...integration
|
|
39
|
-
];
|
|
40
|
-
const frameworksRegex = new RegExp(frameworks.join('|'));
|
|
41
|
-
testPlugins.forEach((testPlugin)=>{
|
|
42
|
-
const match = frameworksRegex.exec(testPlugin);
|
|
43
|
-
if (match) {
|
|
44
|
-
const matchedFramework = match[0];
|
|
45
|
-
if (unit.includes(matchedFramework)) {
|
|
46
|
-
files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/${globIgnore}`);
|
|
47
|
-
} else {
|
|
48
|
-
files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/*`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
async function create(gasket, context) {
|
|
54
|
-
const { files, typescript, apiApp, addApiRoutes = true, testPlugins, pkg, gasketConfig } = context;
|
|
55
|
-
const generatorDir = `${__dirname}/../generator`;
|
|
56
|
-
gasketConfig.addPlugin('pluginFastify', name);
|
|
57
|
-
pkg.add('dependencies', {
|
|
58
|
-
[name]: `^${version}`,
|
|
59
|
-
fastify: devDependencies.fastify
|
|
60
|
-
});
|
|
61
|
-
if (apiApp && addApiRoutes) {
|
|
62
|
-
const globIgnore = typescript ? '!(*.js)' : '!(*.ts)';
|
|
63
|
-
files.add(`${generatorDir}/app/**/${globIgnore}`);
|
|
64
|
-
gasketConfig.addPlugin('pluginRoutes', './plugins/routes-plugin.js');
|
|
65
|
-
createTestFiles({
|
|
66
|
-
files,
|
|
67
|
-
generatorDir,
|
|
68
|
-
testPlugins,
|
|
69
|
-
globIgnore
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
package/cjs/index.cjs
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/// <reference types="@gasket/core" />
|
|
2
|
-
/// <reference types="@gasket/plugin-metadata" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "default", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function() {
|
|
9
|
-
return _default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
const _create = /*#__PURE__*/ _interop_require_default(require("./create.cjs"));
|
|
13
|
-
const _createservers = /*#__PURE__*/ _interop_require_default(require("./create-servers.cjs"));
|
|
14
|
-
const _actions = /*#__PURE__*/ _interop_require_default(require("./actions.cjs"));
|
|
15
|
-
const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
|
|
16
|
-
function _interop_require_default(obj) {
|
|
17
|
-
return obj && obj.__esModule ? obj : {
|
|
18
|
-
default: obj
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const { name, version, description } = _packagejson.default;
|
|
22
|
-
/** @type {import('@gasket/core').Plugin} */ const plugin = {
|
|
23
|
-
name,
|
|
24
|
-
version,
|
|
25
|
-
description,
|
|
26
|
-
actions: _actions.default,
|
|
27
|
-
hooks: {
|
|
28
|
-
create: _create.default,
|
|
29
|
-
createServers: _createservers.default,
|
|
30
|
-
metadata (gasket, meta) {
|
|
31
|
-
return {
|
|
32
|
-
...meta,
|
|
33
|
-
actions: [
|
|
34
|
-
{
|
|
35
|
-
name: 'getFastifyApp',
|
|
36
|
-
description: 'Get the Fastify app instance',
|
|
37
|
-
link: 'README.md#getFastifyApp',
|
|
38
|
-
deprecated: true
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
lifecycles: [
|
|
42
|
-
{
|
|
43
|
-
name: 'fastify',
|
|
44
|
-
method: 'exec',
|
|
45
|
-
description: 'Modify the Fastify instance to for adding endpoints',
|
|
46
|
-
link: 'README.md#express',
|
|
47
|
-
parent: 'createServers',
|
|
48
|
-
after: 'middleware'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: 'errorMiddleware',
|
|
52
|
-
method: 'exec',
|
|
53
|
-
description: 'Add Express style middleware for handling errors with Fastify',
|
|
54
|
-
link: 'README.md#errorMiddleware',
|
|
55
|
-
parent: 'createServers',
|
|
56
|
-
after: 'express'
|
|
57
|
-
}
|
|
58
|
-
],
|
|
59
|
-
configurations: [
|
|
60
|
-
{
|
|
61
|
-
name: 'fastify',
|
|
62
|
-
link: 'README.md#configuration',
|
|
63
|
-
description: 'Fastify configuration object',
|
|
64
|
-
type: 'object'
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: 'fastify.compression',
|
|
68
|
-
link: 'README.md#configuration',
|
|
69
|
-
description: 'Automatic compression',
|
|
70
|
-
type: 'boolean',
|
|
71
|
-
default: true
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: 'fastify.excludedRoutesRegex',
|
|
75
|
-
link: 'README.md#configuration',
|
|
76
|
-
description: 'Routes to be excluded based on a regex',
|
|
77
|
-
type: 'RegExp'
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const _default = plugin;
|
package/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
package/cjs/utils.cjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
alignLogger: function() {
|
|
13
|
-
return alignLogger;
|
|
14
|
-
},
|
|
15
|
-
getAppInstance: function() {
|
|
16
|
-
return getAppInstance;
|
|
17
|
-
},
|
|
18
|
-
testClearAppInstance: function() {
|
|
19
|
-
return testClearAppInstance;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _fastify = /*#__PURE__*/ _interop_require_default(require("fastify"));
|
|
23
|
-
function _interop_require_default(obj) {
|
|
24
|
-
return obj && obj.__esModule ? obj : {
|
|
25
|
-
default: obj
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
const fallbackMap = {
|
|
29
|
-
fatal: 'error',
|
|
30
|
-
trace: 'debug'
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* A helper function to ensure that all the required log levels
|
|
34
|
-
* for a Fastify server are present.
|
|
35
|
-
* @type {import('@gasket/plugin-fastify').alignLogger}
|
|
36
|
-
*/ function alignLogger(logger) {
|
|
37
|
-
const fastifyLogger = logger;
|
|
38
|
-
[
|
|
39
|
-
'fatal',
|
|
40
|
-
'trace'
|
|
41
|
-
].map((level)=>{
|
|
42
|
-
if (!logger[level]) {
|
|
43
|
-
fastifyLogger[level] = logger[fallbackMap[level]];
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
return fastifyLogger;
|
|
47
|
-
}
|
|
48
|
-
let instance = null;
|
|
49
|
-
function getAppInstance(gasket) {
|
|
50
|
-
if (!instance) {
|
|
51
|
-
const { fastify: fastifyConfig = {}, http2, https } = gasket.config;
|
|
52
|
-
const { trustProxy = false, disableRequestLogging = true } = fastifyConfig;
|
|
53
|
-
const fastifyLogger = alignLogger(gasket.logger);
|
|
54
|
-
instance = (0, _fastify.default)({
|
|
55
|
-
logger: fastifyLogger,
|
|
56
|
-
trustProxy,
|
|
57
|
-
https,
|
|
58
|
-
http2,
|
|
59
|
-
disableRequestLogging
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return instance;
|
|
63
|
-
}
|
|
64
|
-
function testClearAppInstance() {
|
|
65
|
-
instance = null;
|
|
66
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const defaultHandler = async (req, res) => {
|
|
2
|
-
if (res.statusCode === 200) {
|
|
3
|
-
res.send({ message: 'Welcome to your default route...' });
|
|
4
|
-
}
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
name: 'routes-plugin',
|
|
9
|
-
hooks: {
|
|
10
|
-
fastify(gasket, app) {
|
|
11
|
-
{{#if useSwagger }}
|
|
12
|
-
/**
|
|
13
|
-
* @swagger
|
|
14
|
-
*
|
|
15
|
-
* /default:
|
|
16
|
-
* get:
|
|
17
|
-
* summary: "Get default route"
|
|
18
|
-
* produces:
|
|
19
|
-
* - "application/json"
|
|
20
|
-
* responses:
|
|
21
|
-
* "200":
|
|
22
|
-
* description: "Returns welcome message."
|
|
23
|
-
* content:
|
|
24
|
-
* application/json
|
|
25
|
-
*/
|
|
26
|
-
{{/if }}
|
|
27
|
-
app.get('/default', defaultHandler);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export const defaultHandler = async (req, res) => {
|
|
2
|
-
if (res.statusCode === 200) {
|
|
3
|
-
res.send({ message: 'Welcome to your default route...' });
|
|
4
|
-
}
|
|
5
|
-
};
|
|
6
|
-
export default {
|
|
7
|
-
name: 'routes-plugin',
|
|
8
|
-
hooks: {
|
|
9
|
-
fastify(gasket, app) {
|
|
10
|
-
{{#if useSwagger }}
|
|
11
|
-
/**
|
|
12
|
-
* @swagger
|
|
13
|
-
*
|
|
14
|
-
* /default:
|
|
15
|
-
* get:
|
|
16
|
-
* summary: "Get default route"
|
|
17
|
-
* produces:
|
|
18
|
-
* - "application/json"
|
|
19
|
-
* responses:
|
|
20
|
-
* "200":
|
|
21
|
-
* description: "Returns welcome message."
|
|
22
|
-
* content:
|
|
23
|
-
* application/json
|
|
24
|
-
*/
|
|
25
|
-
{{/if }}
|
|
26
|
-
app.get('/default', defaultHandler);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{{#if typescript}}
|
|
2
|
-
const config = {
|
|
3
|
-
preset: 'ts-jest/presets/default-esm',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
injectGlobals: true,
|
|
6
|
-
moduleDirectories: ['node_modules', '<rootDir>'],
|
|
7
|
-
moduleNameMapper: {
|
|
8
|
-
'^(\\.{1,2}/.*)\\.js$': '$1'
|
|
9
|
-
},
|
|
10
|
-
transform: {
|
|
11
|
-
'^.+.ts$': ['ts-jest', { useESM: true }]
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default config;
|
|
16
|
-
{{else}}
|
|
17
|
-
export default {
|
|
18
|
-
testEnvironment: 'node',
|
|
19
|
-
injectGlobals: true
|
|
20
|
-
};
|
|
21
|
-
{{/if}}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { jest } from '@jest/globals';
|
|
2
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
3
|
-
|
|
4
|
-
describe('Routes', () => {
|
|
5
|
-
let mockRequest, mockResponse;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
mockRequest = {};
|
|
8
|
-
mockResponse = {
|
|
9
|
-
statusCode: 200,
|
|
10
|
-
send: jest.fn()
|
|
11
|
-
};
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('defaultHandler should use expeced message', async () => {
|
|
15
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
16
|
-
expect(mockResponse.send).toHaveBeenCalledWith({
|
|
17
|
-
message: 'Welcome to your default route...'
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
jest,
|
|
3
|
-
describe,
|
|
4
|
-
beforeEach,
|
|
5
|
-
it,
|
|
6
|
-
expect
|
|
7
|
-
} from '@jest/globals';
|
|
8
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
9
|
-
|
|
10
|
-
describe('Routes', () => {
|
|
11
|
-
let mockRequest, mockResponse;
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
mockRequest = {};
|
|
14
|
-
mockResponse = {
|
|
15
|
-
statusCode: 200,
|
|
16
|
-
send: jest.fn()
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('defaultHandler should use expeced message', async () => {
|
|
21
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
22
|
-
expect(mockResponse.send).toHaveBeenCalledWith({
|
|
23
|
-
message: 'Welcome to your default route...'
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import sinon from 'sinon';
|
|
3
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
4
|
-
|
|
5
|
-
describe('Routes', () => {
|
|
6
|
-
let mockRequest, mockResponse, sendSpy;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
mockRequest = {};
|
|
10
|
-
sendSpy = sinon.spy();
|
|
11
|
-
mockResponse = {
|
|
12
|
-
statusCode: 200,
|
|
13
|
-
send: sendSpy
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('defaultHandler should use expected message', async () => {
|
|
18
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
19
|
-
expect(sendSpy.calledWith({
|
|
20
|
-
message: 'Welcome to your default route...'
|
|
21
|
-
})).to.be.true;
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import sinon from 'sinon';
|
|
3
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
4
|
-
|
|
5
|
-
describe('Routes', () => {
|
|
6
|
-
let mockRequest, mockResponse, sendSpy;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
mockRequest = {};
|
|
10
|
-
sendSpy = sinon.spy();
|
|
11
|
-
mockResponse = {
|
|
12
|
-
statusCode: 200,
|
|
13
|
-
send: sendSpy
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('defaultHandler should use expected message', async () => {
|
|
18
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
19
|
-
expect(sendSpy.calledWith({
|
|
20
|
-
message: 'Welcome to your default route...'
|
|
21
|
-
})).to.be.true;
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { vi, expect } from 'vitest';
|
|
2
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
3
|
-
|
|
4
|
-
describe('Routes', () => {
|
|
5
|
-
let mockRequest, mockResponse;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
mockRequest = {};
|
|
9
|
-
mockResponse = {
|
|
10
|
-
statusCode: 200,
|
|
11
|
-
send: vi.fn()
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('defaultHeader should use expected message', async () => {
|
|
16
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
17
|
-
expect(mockResponse.send).toHaveBeenCalledWith({
|
|
18
|
-
message: 'Welcome to your default route...'
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
import { defaultHandler } from '../plugins/routes-plugin.js';
|
|
3
|
-
|
|
4
|
-
describe('Routes', () => {
|
|
5
|
-
let mockRequest, mockResponse;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
mockRequest = {};
|
|
9
|
-
mockResponse = {
|
|
10
|
-
statusCode: 200,
|
|
11
|
-
send: vi.fn()
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('defaultHeader should use expected message', async () => {
|
|
16
|
-
await defaultHandler(mockRequest, mockResponse);
|
|
17
|
-
expect(mockResponse.send).toHaveBeenCalledWith({
|
|
18
|
-
message: 'Welcome to your default route...'
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
package/lib/create.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/// <reference types="@gasket/core" />
|
|
2
|
-
/// <reference types="create-gasket-app" />
|
|
3
|
-
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import { dirname } from 'path';
|
|
6
|
-
import packageJson from '../package.json' with { type: 'json' };
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const __dirname = dirname(__filename);
|
|
9
|
-
const { name, version, devDependencies } = packageJson;
|
|
10
|
-
|
|
11
|
-
const createTestFiles = ({ files, generatorDir, testPlugins, globIgnore }) => {
|
|
12
|
-
if (!testPlugins || testPlugins.length === 0) return;
|
|
13
|
-
const unit = ['jest', 'mocha', 'vitest'];
|
|
14
|
-
const integration = ['cypress'];
|
|
15
|
-
const frameworks = [...unit, ...integration];
|
|
16
|
-
const frameworksRegex = new RegExp(frameworks.join('|'));
|
|
17
|
-
|
|
18
|
-
testPlugins.forEach((testPlugin) => {
|
|
19
|
-
const match = frameworksRegex.exec(testPlugin);
|
|
20
|
-
if (match) {
|
|
21
|
-
const matchedFramework = match[0];
|
|
22
|
-
if (unit.includes(matchedFramework)) {
|
|
23
|
-
files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/${globIgnore}`);
|
|
24
|
-
} else {
|
|
25
|
-
files.add(`${generatorDir}/${matchedFramework}/*`, `${generatorDir}/${matchedFramework}/**/*`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Add files & extend package.json for new apps.
|
|
33
|
-
* @type {import('@gasket/core').HookHandler<'create'>}
|
|
34
|
-
*/
|
|
35
|
-
export default async function create(gasket, context) {
|
|
36
|
-
const {
|
|
37
|
-
files,
|
|
38
|
-
typescript,
|
|
39
|
-
apiApp,
|
|
40
|
-
addApiRoutes = true,
|
|
41
|
-
testPlugins,
|
|
42
|
-
pkg,
|
|
43
|
-
gasketConfig
|
|
44
|
-
} = context;
|
|
45
|
-
const generatorDir = `${__dirname}/../generator`;
|
|
46
|
-
|
|
47
|
-
gasketConfig.addPlugin('pluginFastify', name);
|
|
48
|
-
|
|
49
|
-
pkg.add('dependencies', {
|
|
50
|
-
[name]: `^${version}`,
|
|
51
|
-
fastify: devDependencies.fastify
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (apiApp && addApiRoutes) {
|
|
55
|
-
const globIgnore = typescript ? '!(*.js)' : '!(*.ts)';
|
|
56
|
-
files.add(`${generatorDir}/app/**/${globIgnore}`);
|
|
57
|
-
gasketConfig.addPlugin('pluginRoutes', './plugins/routes-plugin.js');
|
|
58
|
-
|
|
59
|
-
createTestFiles({ files, generatorDir, testPlugins, globIgnore });
|
|
60
|
-
}
|
|
61
|
-
}
|