@uscreen.de/create-fastify-app 1.1.1 → 1.1.3
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/.github/workflows/main.yml +3 -3
- package/README.md +13 -1
- package/package.json +5 -5
- package/skeleton/.nvmrc +1 -1
- package/test/_arena/new-app/.editorconfig +0 -13
- package/test/_arena/new-app/.env.example +0 -4
- package/test/_arena/new-app/.envrc +0 -4
- package/test/_arena/new-app/.eslintrc +0 -3
- package/test/_arena/new-app/.gitignore +0 -7
- package/test/_arena/new-app/.gitlab-ci.yml.example +0 -25
- package/test/_arena/new-app/.husky/_/.gitignore +0 -1
- package/test/_arena/new-app/.nvmrc +0 -1
- package/test/_arena/new-app/.taprc +0 -7
- package/test/_arena/new-app/Makefile +0 -11
- package/test/_arena/new-app/README.md +0 -38
- package/test/_arena/new-app/app/app.js +0 -17
- package/test/_arena/new-app/app/config.js +0 -34
- package/test/_arena/new-app/app/plugins/noop.js +0 -14
- package/test/_arena/new-app/app/schemas.js +0 -34
- package/test/_arena/new-app/app/server.js +0 -37
- package/test/_arena/new-app/app/services/noop.js +0 -22
- package/test/_arena/new-app/package.json +0 -40
- package/test/_arena/new-app/test/app/noop.test.js +0 -54
- package/test/_arena/new-app/test/helper.js +0 -29
|
@@ -5,16 +5,16 @@ name: Test CI
|
|
|
5
5
|
|
|
6
6
|
on:
|
|
7
7
|
push:
|
|
8
|
-
branches: ["
|
|
8
|
+
branches: ["main"]
|
|
9
9
|
pull_request:
|
|
10
|
-
branches: ["
|
|
10
|
+
branches: ["main"]
|
|
11
11
|
|
|
12
12
|
jobs:
|
|
13
13
|
test:
|
|
14
14
|
runs-on: ubuntu-latest
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
|
-
node-version: [
|
|
17
|
+
node-version: [18, 20]
|
|
18
18
|
steps:
|
|
19
19
|
- name: Checkout code
|
|
20
20
|
uses: actions/checkout@v3
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# create-fastify-app
|
|
2
2
|
|
|
3
3
|
[](https://github.com/uscreen/create-fastify-app/actions/workflows/main.yml)
|
|
4
|
-
[](https://coveralls.io/github/uscreen/create-fastify-app?branch=main)
|
|
5
5
|
[](https://snyk.io/test/github/uscreen/create-fastify-app?targetFile=package.json)
|
|
6
6
|
[](https://badge.fury.io/js/@uscreen.de%2Fcreate-fastify-app)
|
|
7
7
|
|
|
@@ -73,6 +73,18 @@ $ make logs
|
|
|
73
73
|
|
|
74
74
|
## Changelog
|
|
75
75
|
|
|
76
|
+
### 1.1.2
|
|
77
|
+
|
|
78
|
+
#### Changed
|
|
79
|
+
|
|
80
|
+
- upgraded to node 20.x (LTS)
|
|
81
|
+
|
|
82
|
+
### 1.1.1
|
|
83
|
+
|
|
84
|
+
#### Changed
|
|
85
|
+
|
|
86
|
+
- upgraded to node 18.x (LTS)
|
|
87
|
+
|
|
76
88
|
### 1.1.0
|
|
77
89
|
|
|
78
90
|
#### Changed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uscreen.de/create-fastify-app",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "cli to create a new @uscreen.de/fastify-app",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"prepare": "husky install"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"commander": "^
|
|
25
|
+
"commander": "^11.0.0",
|
|
26
26
|
"fs-extra": "^11.1.0",
|
|
27
|
-
"read-pkg-up": "^
|
|
28
|
-
"write-pkg": "^
|
|
27
|
+
"read-pkg-up": "^10.0.0",
|
|
28
|
+
"write-pkg": "^6.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@uscreen.de/eslint-config-prettystandard-node": "^0.2.10",
|
|
32
|
-
"c8": "^
|
|
32
|
+
"c8": "^8.0.0",
|
|
33
33
|
"husky": ">=8.0.2",
|
|
34
34
|
"lint-staged": ">=13.0.3",
|
|
35
35
|
"strip-ansi": "^7.0.1",
|
package/skeleton/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
20
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
charset = utf-8
|
|
5
|
-
indent_style = space
|
|
6
|
-
indent_size = 2
|
|
7
|
-
end_of_line = lf
|
|
8
|
-
insert_final_newline = true
|
|
9
|
-
trim_trailing_whitespace = true
|
|
10
|
-
|
|
11
|
-
[{Makefile,**.mk}]
|
|
12
|
-
# Use tabs for indentation (Makefiles require tabs)
|
|
13
|
-
indent_style = tab
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# image: node:lts-alpine
|
|
2
|
-
|
|
3
|
-
# cache:
|
|
4
|
-
# paths:
|
|
5
|
-
# - node_modules/
|
|
6
|
-
# - .yarn
|
|
7
|
-
|
|
8
|
-
# stages:
|
|
9
|
-
# - test
|
|
10
|
-
# - audit
|
|
11
|
-
|
|
12
|
-
# test:
|
|
13
|
-
# stage: test
|
|
14
|
-
# script:
|
|
15
|
-
# - npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
|
|
16
|
-
# - yarn install --pure-lockfile --cache-folder .yarn
|
|
17
|
-
# - yarn test:ci
|
|
18
|
-
# coverage: '/^Statements\s*:\s*([^%]+)/'
|
|
19
|
-
|
|
20
|
-
# audit:
|
|
21
|
-
# stage: audit
|
|
22
|
-
# only:
|
|
23
|
-
# - schedules
|
|
24
|
-
# script:
|
|
25
|
-
# - yarn audit
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
*
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
18
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# ${app-name}
|
|
2
|
-
|
|
3
|
-
> __TODO:__
|
|
4
|
-
> add a name & short description of this apps purpose
|
|
5
|
-
|
|
6
|
-
## Usage
|
|
7
|
-
|
|
8
|
-
* `make start`: start app on local dev
|
|
9
|
-
* `make test`: test app
|
|
10
|
-
|
|
11
|
-
## Configure
|
|
12
|
-
|
|
13
|
-
Configuration is read by dotenv from `app/.env` file and validated _[optional modified]_ by `app/config.js`. Please add extra defaults if needed to `config.js`. Default values should __always__ refer to local dev setups.
|
|
14
|
-
|
|
15
|
-
> __Note:__
|
|
16
|
-
> the `.env` file should __never__ get pushed to repository. So adding secrets and credentials to `.env` can be considered a secure option bound to specific environments.
|
|
17
|
-
|
|
18
|
-
## Api
|
|
19
|
-
|
|
20
|
-
After starting your server you will find swagger documenation at [http://127.0.0.1:3000/api/docs/](http://127.0.0.1:3000/api/docs/) to explore web api requests interactively.
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## Roadmap
|
|
25
|
-
|
|
26
|
-
> TBD
|
|
27
|
-
|
|
28
|
-
## Changelog
|
|
29
|
-
|
|
30
|
-
### v0.0.0
|
|
31
|
-
|
|
32
|
-
- initially bootstrapped by `yarn create @uscreen.de/fastify-app`
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
## Credits
|
|
37
|
-
|
|
38
|
-
application [boilerplate](https://www.npmjs.com/package/@uscreen.de/fastify-app) provided by [u|screen](https://uscreen.de)
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import fastifyApp from '@uscreen.de/fastify-app'
|
|
2
|
-
import fp from 'fastify-plugin'
|
|
3
|
-
import schemas from './schemas.js'
|
|
4
|
-
|
|
5
|
-
export default fp((fastify, opts, next) => {
|
|
6
|
-
/**
|
|
7
|
-
* add schemas
|
|
8
|
-
*/
|
|
9
|
-
fastify.register(schemas)
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* register app
|
|
13
|
-
*/
|
|
14
|
-
fastify.register(fastifyApp, opts)
|
|
15
|
-
|
|
16
|
-
next()
|
|
17
|
-
})
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import envSchema from 'env-schema'
|
|
2
|
-
import CommonESM from '@uscreen.de/common-esm'
|
|
3
|
-
|
|
4
|
-
const { join } = new CommonESM(import.meta.url)
|
|
5
|
-
|
|
6
|
-
const schema = {
|
|
7
|
-
type: 'object',
|
|
8
|
-
properties: {
|
|
9
|
-
httpPort: { default: 3000 },
|
|
10
|
-
httpBind: { default: '127.0.0.1' },
|
|
11
|
-
prefix: { default: '/api' },
|
|
12
|
-
logEnabled: { default: true },
|
|
13
|
-
logLevel: { default: 'info' }
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const config = envSchema({
|
|
18
|
-
schema: schema,
|
|
19
|
-
dotenv: true
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
config.autoloads = [join('plugins'), join('services')]
|
|
23
|
-
|
|
24
|
-
config.swagger = {
|
|
25
|
-
routePrefix: `${config.prefix}/docs`,
|
|
26
|
-
exposeRoute: true,
|
|
27
|
-
addModels: true
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
config.health = {
|
|
31
|
-
exposeStatusRoute: `${config.prefix}/health`
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default config
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import fp from 'fastify-plugin'
|
|
2
|
-
import S from 'fluent-json-schema'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Usage of the Globaly Shared Schema feature
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export default fp((fastify, opts, next) => {
|
|
9
|
-
const addSchema = (schema) => {
|
|
10
|
-
fastify.addSchema(schema)
|
|
11
|
-
return schema
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* add generic schemas
|
|
16
|
-
*/
|
|
17
|
-
const noop = addSchema(S.object().id('noop').prop('noop'))
|
|
18
|
-
|
|
19
|
-
const plugin = addSchema(S.object().id('plugin').prop('plugin'))
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* combine and extend schemas
|
|
23
|
-
*/
|
|
24
|
-
addSchema(
|
|
25
|
-
S.object()
|
|
26
|
-
.id('noopNplugin')
|
|
27
|
-
.required(['noop'])
|
|
28
|
-
// .prop('property') // --> strip it
|
|
29
|
-
.extend(noop)
|
|
30
|
-
.extend(plugin)
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
next()
|
|
34
|
-
})
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import fastify from 'fastify'
|
|
2
|
-
import { options } from '@uscreen.de/fastify-app'
|
|
3
|
-
import config from './config.js'
|
|
4
|
-
import app from './app.js'
|
|
5
|
-
|
|
6
|
-
const server = fastify(options(config))
|
|
7
|
-
|
|
8
|
-
server.register(app, config)
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* post-treatment
|
|
12
|
-
*/
|
|
13
|
-
server.ready((err) => {
|
|
14
|
-
if (err) throw err
|
|
15
|
-
server.log.debug(
|
|
16
|
-
'server ready, routes are set:\n' +
|
|
17
|
-
server.printRoutes({ commonPrefix: false })
|
|
18
|
-
)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* graceful shutdown (closing handles, etc.)
|
|
23
|
-
*/
|
|
24
|
-
const shutdown = async () => {
|
|
25
|
-
server.log.info(
|
|
26
|
-
`application shutting down. (${server.app.name} ${server.app.version})`
|
|
27
|
-
)
|
|
28
|
-
await server.close()
|
|
29
|
-
process.exit()
|
|
30
|
-
}
|
|
31
|
-
process.on('SIGINT', shutdown)
|
|
32
|
-
process.on('SIGTERM', shutdown)
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* start http server
|
|
36
|
-
*/
|
|
37
|
-
server.listen({ port: config.httpPort, host: config.httpBind })
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export default (fastify, opts, next) => {
|
|
2
|
-
fastify.get(
|
|
3
|
-
'/noop',
|
|
4
|
-
{
|
|
5
|
-
schema: {
|
|
6
|
-
response: {
|
|
7
|
-
200: { $ref: 'noopNplugin#' } // fastest and json-schema spec compatiple way, or use 'fastify.getSchema()'
|
|
8
|
-
// 200: fastify.getSchema('noopNplugin')
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
async (req, res) => {
|
|
13
|
-
return {
|
|
14
|
-
noop: 'Hello world',
|
|
15
|
-
plugin: fastify.noop(),
|
|
16
|
-
property: 'should be stripped from response'
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
next()
|
|
22
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "new-app",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"main": "app/server.js",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Martin Herting",
|
|
7
|
-
"email": "herting@uscreen.de"
|
|
8
|
-
},
|
|
9
|
-
"license": "MIT",
|
|
10
|
-
"type": "module",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"dev": "nodemon",
|
|
13
|
-
"lint": "eslint --fix",
|
|
14
|
-
"test": "c8 tap",
|
|
15
|
-
"test:cov": "c8 --reporter=html --reporter=text tap",
|
|
16
|
-
"test:ci": "tap",
|
|
17
|
-
"prepare": "husky install"
|
|
18
|
-
},
|
|
19
|
-
"lint-staged": {
|
|
20
|
-
"*.js": "eslint --cache --fix"
|
|
21
|
-
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@uscreen.de/common-esm": "^1.0.0",
|
|
24
|
-
"@uscreen.de/fastify-app": "^1.0.0-0",
|
|
25
|
-
"env-schema": "^5.1.1",
|
|
26
|
-
"fastify": "^4.10.2",
|
|
27
|
-
"fastify-plugin": "^4.3.0",
|
|
28
|
-
"fluent-json-schema": "^4.0.0",
|
|
29
|
-
"pino-pretty": "^9.1.1"
|
|
30
|
-
},
|
|
31
|
-
"devDependencies": {
|
|
32
|
-
"@uscreen.de/eslint-config-prettystandard-node": "^0.2.8",
|
|
33
|
-
"c8": "^7.12.0",
|
|
34
|
-
"husky": ">=6",
|
|
35
|
-
"lint-staged": ">=10",
|
|
36
|
-
"nodemon": "^2.0.20",
|
|
37
|
-
"prettier": "^2.8.0",
|
|
38
|
-
"tap": "^16.3.2"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import tap from 'tap'
|
|
2
|
-
import { build } from '../helper.js'
|
|
3
|
-
|
|
4
|
-
tap.test('Test Setup', (t) => {
|
|
5
|
-
t.equal(true, true, 'Tests and assertions should work')
|
|
6
|
-
t.end()
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
tap.test('Healthcheck', async (t) => {
|
|
10
|
-
const fastify = await build(t)
|
|
11
|
-
const { prefix } = fastify.config
|
|
12
|
-
|
|
13
|
-
t.test('a valid GET Request', (t) => {
|
|
14
|
-
fastify.inject(
|
|
15
|
-
{
|
|
16
|
-
method: 'GET',
|
|
17
|
-
url: `${prefix}/health`
|
|
18
|
-
},
|
|
19
|
-
(e, response) => {
|
|
20
|
-
t.error(e)
|
|
21
|
-
t.same(response.statusCode, 200, 'response ok')
|
|
22
|
-
t.same(JSON.parse(response.body), { status: 'ok' }, 'payload ok')
|
|
23
|
-
t.end()
|
|
24
|
-
}
|
|
25
|
-
)
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
tap.test('Noop Service', async (t) => {
|
|
30
|
-
const fastify = await build(t)
|
|
31
|
-
const { prefix } = fastify.config
|
|
32
|
-
|
|
33
|
-
t.test('a valid GET Request', (t) => {
|
|
34
|
-
fastify.inject(
|
|
35
|
-
{
|
|
36
|
-
method: 'GET',
|
|
37
|
-
url: `${prefix}/noop`
|
|
38
|
-
},
|
|
39
|
-
(e, response) => {
|
|
40
|
-
t.error(e)
|
|
41
|
-
t.same(response.statusCode, 200, 'response ok')
|
|
42
|
-
t.same(
|
|
43
|
-
JSON.parse(response.body),
|
|
44
|
-
{
|
|
45
|
-
noop: 'Hello world',
|
|
46
|
-
plugin: 'Hello Universe'
|
|
47
|
-
},
|
|
48
|
-
'payload ok'
|
|
49
|
-
)
|
|
50
|
-
t.end()
|
|
51
|
-
}
|
|
52
|
-
)
|
|
53
|
-
})
|
|
54
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// This file contains code that we reuse
|
|
2
|
-
// between our tests.
|
|
3
|
-
|
|
4
|
-
import Fastify from 'fastify'
|
|
5
|
-
import fp from 'fastify-plugin'
|
|
6
|
-
|
|
7
|
-
// setup to import YOUR app
|
|
8
|
-
import App from '../app/app.js'
|
|
9
|
-
import Config from '../app/config.js'
|
|
10
|
-
|
|
11
|
-
// automatically build and tear down our instance
|
|
12
|
-
export const build = async (t, ConfigOverwrite = {}) => {
|
|
13
|
-
return new Promise((resolve) => {
|
|
14
|
-
const app = Fastify()
|
|
15
|
-
|
|
16
|
-
// setup to register YOUR app
|
|
17
|
-
app.register(fp(App), { ...Config, ...ConfigOverwrite })
|
|
18
|
-
|
|
19
|
-
// tear down our app after we are done
|
|
20
|
-
t.teardown(app.close.bind(app))
|
|
21
|
-
|
|
22
|
-
app.ready((err) => {
|
|
23
|
-
if (err) throw err
|
|
24
|
-
resolve(app)
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|