-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add application scaffolding from chapter 6 * fix: merge updates
- Loading branch information
Showing
30 changed files
with
16,344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ typings/ | |
.coveralls.yml | ||
|
||
package-lock.json | ||
!Chapter 9/package-lock.json | ||
|
||
demo/* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NODE_ENV=development | ||
PORT=3001 | ||
MONGO_URL=mongodb://localhost:27017/todo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"extends": "standard"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM node:16-alpine | ||
|
||
# set envs | ||
ENV HOME=/home/app | ||
ENV APP_HOME=$HOME/node/ | ||
ENV NODE_ENV=production | ||
|
||
# add app dependencies | ||
COPY package.json $APP_HOME | ||
COPY package-lock.json $APP_HOME | ||
|
||
# change workgin dir and install deps | ||
WORKDIR $APP_HOME | ||
RUN npm ci --only=production | ||
|
||
# copy all app files | ||
COPY --chown=node:node . $APP_HOME | ||
|
||
# dumb-init registers signal handlers for every signal that can be caught | ||
RUN apk update && apk add --no-cache dumb-init | ||
|
||
# run app with low permissions level user | ||
USER node | ||
|
||
EXPOSE 3000 | ||
ENTRYPOINT ["dumb-init"] | ||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Backend Cafe | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Chapter 9 - Application testing | ||
|
||
This chapter will implements the tests for our project by running the application and mocking when necessary. | ||
|
||
## How to use this folder? | ||
|
||
In this folder you will find the source code of the chapter. | ||
The filenames are the same as the chapter's sections. | ||
|
||
Install the application first by running: | ||
|
||
``` | ||
npm ci | ||
``` | ||
|
||
You can run the chapter's code by starting the application: | ||
|
||
```bash | ||
npm test | ||
``` | ||
|
||
⚠️ You need a running `docker` application to run the tests. | ||
|
||
Before running the code examples, you need to install the dependencies running `npm install`. | ||
|
||
## Trouble? | ||
|
||
If you encounter any problems while reading the chapter or while running the code examples, | ||
you can ask for help on the [official Discord chat](TODO) TODO LINK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const AutoLoad = require('fastify-autoload') | ||
|
||
module.exports = async function (fastify, opts) { | ||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'schemas'), | ||
indexPattern: /^loader.js$/i | ||
}) | ||
|
||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'plugins'), | ||
dirNameRoutePrefix: false, | ||
ignorePattern: /.*.no-load\.js/, | ||
// ignorePattern: /^((?!load\.js).)*$/, | ||
indexPattern: /^no$/i, | ||
options: Object.assign({}, opts) | ||
}) | ||
|
||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'routes'), | ||
indexPattern: /.*routes(\.js|\.cjs)$/i, | ||
ignorePattern: /.*\.js/, | ||
autoHooksPattern: /.*hooks(\.js|\.cjs)$/i, | ||
autoHooks: true, | ||
cascadeHooks: true, | ||
options: Object.assign({}, opts) | ||
}) | ||
} | ||
|
||
module.exports.options = require('./configs/server-options') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
module.exports = { | ||
ajv: { | ||
customOptions: { | ||
coerceTypes: 'array', | ||
removeAdditional: 'all' | ||
} | ||
} | ||
} |
Oops, something went wrong.