├── .dockerignore
├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.md
├── .gitignore
├── CODE_OF_CONDUCT.md
├── Dockerfile
├── LICENSE
├── README.md
├── chart
└── base
│ ├── .helmignore
│ ├── Chart.yaml
│ └── values.yaml
├── licenses
└── LICENSE.txt
├── nest-cli.json
├── package-lock.json
├── package.json
├── public
└── index.html
├── src
├── app.module.ts
├── controllers
│ ├── hello-world
│ │ ├── hello-world.controller.spec.ts
│ │ ├── hello-world.controller.ts
│ │ └── index.ts
│ └── index.ts
├── main.ts
└── services
│ ├── hello-world
│ ├── hello-world.api.ts
│ ├── hello-world.service.ts
│ └── index.ts
│ └── index.ts
├── test
├── app.e2e-spec.ts
├── jest-e2e.json
└── pact-verity.ts
├── tsconfig.build.json
└── tsconfig.json
/.dockerignore:
--------------------------------------------------------------------------------
1 | .git
2 | .cache
3 |
4 | node_modules/
5 |
6 | Jenkinsfile
7 | CODE_OF_CONDUCT.md
8 | LICENSE
9 | README.md
10 | chart/
11 | dist/
12 | docs/
13 | test-report.xml
14 | setup-template.sh
15 | update-template.sh
16 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | node_modules/
3 | *.iml
4 | dist/
5 | coverage/
6 | logs/
7 | .helm/
8 | pipeline-build-config.json
9 | test-report.xml
10 | .scannerwork/
11 |
12 | # Chart dependencies
13 | **/charts/*.tgz
14 | Chart.lock
15 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at mjperrin@us.ibm.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM registry.access.redhat.com/ubi9/nodejs-18:1-62.1692771036 AS builder
2 |
3 | WORKDIR /opt/app-root/src
4 |
5 | COPY --chown=default:root . .
6 |
7 | RUN mkdir -p /opt/app-root/src/node_modules && \
8 | ls -lA && \
9 | npm ci && \
10 | npm run build
11 |
12 | FROM registry.access.redhat.com/ubi9/nodejs-18-minimal:1-67
13 |
14 | ## Uncomment the below lines to update image security content if any
15 | # USER root
16 | # RUN dnf -y update-minimal --security --sec-severity=Important --sec-severity=Critical && dnf clean all
17 |
18 | LABEL name="ibm/template-node-typescript" \
19 | vendor="IBM" \
20 | version="1" \
21 | release="67" \
22 | summary="This is an example of a container image." \
23 | description="This container image will deploy a Typescript Node App"
24 |
25 | WORKDIR /opt/app-root/src
26 |
27 | COPY --from=builder --chown=1001:root /opt/app-root/src/dist dist
28 |
29 | COPY --chown=1001:root package*.json ./
30 |
31 | RUN ls -lA && \
32 | mkdir -p /opt/app-root/src/node_modules && \
33 | npm ci --only=production
34 |
35 | COPY --chown=1001:root licenses licenses
36 | COPY --chown=1001:root public public
37 | # COPY --chown=1001:root licenses /licenses
38 |
39 | ENV HOST=0.0.0.0 PORT=3000
40 |
41 | EXPOSE 3000/tcp
42 |
43 | CMD ["npm", "run", "start"]
44 |
45 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Licensed under the Apache License, Version 2.0 (the "License");
190 | you may not use this file except in compliance with the License.
191 | You may obtain a copy of the License at
192 |
193 | http://www.apache.org/licenses/LICENSE-2.0
194 |
195 | Unless required by applicable law or agreed to in writing, software
196 | distributed under the License is distributed on an "AS IS" BASIS,
197 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
198 | See the License for the specific language governing permissions and
199 | limitations under the License.
200 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | # TypeScript Microservice or Backend for Frontend with Node.js
16 |
17 | This Starter Kit Template can be the foundation of a TypeScript Node.js Microservice or Backend for Frontend.
18 |
19 |
20 | ## Features
21 |
22 | The starter kit provides the following features:
23 |
24 | - Built with [TypeScript](https://www.typescriptlang.org/)
25 | - [nestjs](https://nestjs.com/) framework
26 | - TDD environment with [Jest](https://jestjs.io/)
27 | - Pact testing [Pact](https://docs.pact.io/)
28 |
29 | #### Native Application Development
30 |
31 | Install the latest [Node.js](https://nodejs.org/en/download/) 18+ LTS version.
32 |
33 | After you have created a new git repo from this git template, remember to rename the project.
34 | Edit `package.json` and change the default name to the name you used to create the template.
35 |
36 | Once the Node toolchain has been installed, you can download the project dependencies with:
37 |
38 | ```shell
39 | npm ci
40 | npm run build
41 | npm run start
42 | ```
43 |
44 | ### Deploying
45 |
46 | Make sure you are logged into the IBM Cloud using the IBM Cloud CLI and have access
47 | to your development cluster.
48 |
49 | ```shell
50 | curl -sL https://cli.cloudnativetoolkit.dev/install.sh | sh
51 | ibmcloud login -a cloud.ibm.com -r -g
52 | ibmcloud ks cluster-config --cluster
53 | kubectl get pods
54 |
55 | ```
56 |
57 | Use the Cloud Native Toolkit CLI to register the GIT Repo with CI environment
58 | ```shell
59 | oc pipeline
60 | ```
61 |
62 | ## More Details
63 |
64 | For more details on how to use this Starter Kit Template please review the [Cloud Native Toolkit Developer Guide](https://develop.cloudnativetoolkit.dev/)
65 |
66 | ## Next Steps
67 |
68 | * Learn more about augmenting your Node.js applications on IBM Cloud with the [Node Programming Guide](https://cloud.ibm.com/docs/node?topic=nodejs-getting-started).
69 |
70 | ## License
71 |
72 | This sample application is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the [Developer Certificate of Origin, Version 1.1](https://developercertificate.org/) and the [Apache License, Version 2](https://www.apache.org/licenses/LICENSE-2.0.txt).
73 |
74 | [Apache License FAQ](https://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN)
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/chart/base/.helmignore:
--------------------------------------------------------------------------------
1 | # Patterns to ignore when building packages.
2 | # This supports shell glob matching, relative path matching, and
3 | # negation (prefixed with !). Only one pattern per line.
4 | .DS_Store
5 | # Common VCS dirs
6 | .git/
7 | .gitignore
8 | .bzr/
9 | .bzrignore
10 | .hg/
11 | .hgignore
12 | .svn/
13 | # Common backup files
14 | *.swp
15 | *.bak
16 | *.tmp
17 | *.orig
18 | *~
19 | # Various IDEs
20 | .project
21 | .idea/
22 | *.tmproj
23 | .vscode/
24 |
--------------------------------------------------------------------------------
/chart/base/Chart.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v2
2 | name: base
3 | description: A Helm chart for Kubernetes
4 |
5 | # A chart can be either an 'application' or a 'library' chart.
6 | #
7 | # Application charts are a collection of templates that can be packaged into versioned archives
8 | # to be deployed.
9 | #
10 | # Library charts provide useful utilities or functions for the chart developer. They're included as
11 | # a dependency of application charts to inject those utilities and functions into the rendering
12 | # pipeline. Library charts do not define any templates and therefore cannot be deployed.
13 | type: application
14 |
15 | # This is the chart version. This version number should be incremented each time you make changes
16 | # to the chart and its templates, including the app version.
17 | # Versions are expected to follow Semantic Versioning (https://semver.org/)
18 | version: 0.1.0
19 |
20 | # This is the version number of the application being deployed. This version number should be
21 | # incremented each time you make changes to the application. Versions are not expected to
22 | # follow Semantic Versioning. They should reflect the version the application is using.
23 | appVersion: 0.1.0
24 |
25 | dependencies:
26 | - name: starter-kit
27 | version: 0.6.2
28 | repository: https://charts.cloudnativetoolkit.dev
29 | alias: base
30 |
--------------------------------------------------------------------------------
/chart/base/values.yaml:
--------------------------------------------------------------------------------
1 | global:
2 | tlsSecretName: ""
3 | ingressSubdomain: ""
4 |
5 | base:
6 | runtime: nodejs
7 |
8 | image:
9 | repository: bitnami/nginx
10 | port: 3000
11 | probePath: /
12 | # Overrides the image tag whose default is the chart appVersion.
13 | tag: ""
14 |
15 | autoscaling:
16 | enabled: false
17 | minReplicas: 1
18 | maxReplicas: 100
19 | targetCPUUtilizationPercentage: 80
20 |
21 | # resources: {}
22 | # We usually recommend not to specify default resources and to leave this as a conscious
23 | # choice for the user. This also increases chances charts run on environments with little
24 | # resources, such as Minikube. If you do want to specify resources, uncomment the following
25 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
26 | # limits:
27 | # cpu: 100m
28 | # memory: 128Mi
29 | # requests:
30 | # cpu: 100m
31 | # memory: 128Mi
32 |
33 | route:
34 | enabled: true
35 |
36 | ingress:
37 | enabled: false
38 |
39 | env:
40 | - name: IMAGE_NAME
41 | valueFrom:
42 | fieldRef:
43 | apiVersion: v1
44 | fieldPath: metadata.name
45 | - name: LOG_LEVEL
46 | value: "debug"
47 |
48 | envFrom:
49 | - configMapRef:
50 | name: jaeger-config
51 | optional: true
52 | - secretRef:
53 | name: jaeger-access
54 | optional: true
55 |
--------------------------------------------------------------------------------
/licenses/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Licensed under the Apache License, Version 2.0 (the "License");
190 | you may not use this file except in compliance with the License.
191 | You may obtain a copy of the License at
192 |
193 | http://www.apache.org/licenses/LICENSE-2.0
194 |
195 | Unless required by applicable law or agreed to in writing, software
196 | distributed under the License is distributed on an "AS IS" BASIS,
197 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
198 | See the License for the specific language governing permissions and
199 | limitations under the License.
200 |
--------------------------------------------------------------------------------
/nest-cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/nest-cli",
3 | "collection": "@nestjs/schematics",
4 | "sourceRoot": "src",
5 | "compilerOptions": {
6 | "deleteOutDir": true
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "template-node-typescript-new",
3 | "version": "0.0.1",
4 | "description": "",
5 | "author": "",
6 | "private": true,
7 | "license": "UNLICENSED",
8 | "scripts": {
9 | "build": "nest build",
10 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
11 | "start": "nest start",
12 | "start:dev": "nest start --watch",
13 | "start:debug": "nest start --debug --watch",
14 | "start:prod": "node dist/main",
15 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
16 | "test": "jest",
17 | "test:watch": "jest --watch",
18 | "test:cov": "jest --coverage",
19 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
20 | "test:e2e": "jest --config ./test/jest-e2e.json"
21 | },
22 | "dependencies": {
23 | "@nestjs/common": "^10.0.0",
24 | "@nestjs/core": "^10.0.0",
25 | "@nestjs/platform-express": "^10.0.0",
26 | "@pact-foundation/pact": "^12.1.0",
27 | "reflect-metadata": "^0.1.13",
28 | "rxjs": "^7.8.1"
29 | },
30 | "devDependencies": {
31 | "@nestjs/cli": "^10.0.0",
32 | "@nestjs/schematics": "^10.0.0",
33 | "@nestjs/testing": "^10.0.0",
34 | "@types/express": "^4.17.17",
35 | "@types/jest": "^29.5.2",
36 | "@types/node": "^20.3.1",
37 | "@types/supertest": "^2.0.12",
38 | "@typescript-eslint/eslint-plugin": "^6.0.0",
39 | "@typescript-eslint/parser": "^6.0.0",
40 | "eslint": "^8.42.0",
41 | "eslint-config-prettier": "^9.0.0",
42 | "eslint-plugin-prettier": "^5.0.0",
43 | "jest": "^29.5.0",
44 | "prettier": "^3.0.0",
45 | "source-map-support": "^0.5.21",
46 | "supertest": "^6.3.3",
47 | "ts-jest": "^29.1.0",
48 | "ts-loader": "^9.4.3",
49 | "ts-node": "^10.9.1",
50 | "tsconfig-paths": "^4.2.0",
51 | "typescript": "^5.1.3"
52 | },
53 | "jest": {
54 | "moduleFileExtensions": [
55 | "js",
56 | "json",
57 | "ts"
58 | ],
59 | "rootDir": "src",
60 | "testRegex": ".*\\.spec\\.ts$",
61 | "transform": {
62 | "^.+\\.(t|j)s$": "ts-jest"
63 | },
64 | "collectCoverageFrom": [
65 | "**/*.(t|j)s"
66 | ],
67 | "coverageDirectory": "../coverage",
68 | "testEnvironment": "node"
69 | },
70 | "engines": {
71 | "node": ">= 18.0.0"
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Example API
7 |
8 |
9 | Swagger api docs
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/app.module.ts:
--------------------------------------------------------------------------------
1 | import { Module } from '@nestjs/common';
2 |
3 | import { controllers } from './controllers';
4 | import { providers } from './services';
5 |
6 | @Module({
7 | imports: [],
8 | controllers,
9 | providers,
10 | })
11 | export class AppModule {}
12 |
--------------------------------------------------------------------------------
/src/controllers/hello-world/hello-world.controller.spec.ts:
--------------------------------------------------------------------------------
1 | import { Test, TestingModule } from '@nestjs/testing';
2 |
3 | import { HelloWorldController } from './hello-world.controller';
4 | import { provider as helloWorldProvider } from '../../services/hello-world';
5 |
6 | describe('AppController', () => {
7 | let appController: HelloWorldController;
8 |
9 | beforeEach(async () => {
10 | const app: TestingModule = await Test.createTestingModule({
11 | controllers: [HelloWorldController],
12 | providers: [helloWorldProvider],
13 | }).compile();
14 |
15 | appController = app.get(HelloWorldController);
16 | });
17 |
18 | describe('root', () => {
19 | it('should return "Hello World!"', () => {
20 | expect(appController.getHello()).toBe('Hello World!');
21 | });
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/src/controllers/hello-world/hello-world.controller.ts:
--------------------------------------------------------------------------------
1 | import { Controller, Get } from '@nestjs/common';
2 | import { HelloWorldApi } from '../../services';
3 |
4 | @Controller()
5 | export class HelloWorldController {
6 | constructor(private readonly service: HelloWorldApi) {}
7 |
8 | @Get()
9 | getHello(): string {
10 | return this.service.getHello();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/controllers/hello-world/index.ts:
--------------------------------------------------------------------------------
1 | export * from './hello-world.controller';
2 |
--------------------------------------------------------------------------------
/src/controllers/index.ts:
--------------------------------------------------------------------------------
1 | import { HelloWorldController } from './hello-world';
2 |
3 | export * from './hello-world';
4 |
5 | export const controllers = [HelloWorldController];
6 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { NestFactory } from '@nestjs/core';
2 | import { AppModule } from './app.module';
3 |
4 | async function bootstrap() {
5 | const app = await NestFactory.create(AppModule);
6 | await app.listen(3000);
7 | }
8 | bootstrap().catch(err => console.error(err));
9 |
--------------------------------------------------------------------------------
/src/services/hello-world/hello-world.api.ts:
--------------------------------------------------------------------------------
1 |
2 | export abstract class HelloWorldApi {
3 | abstract getHello()
4 | }
5 |
--------------------------------------------------------------------------------
/src/services/hello-world/hello-world.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@nestjs/common';
2 | import {HelloWorldApi} from "./hello-world.api";
3 |
4 | @Injectable()
5 | export class HelloWorldService implements HelloWorldApi {
6 | getHello(): string {
7 | return 'Hello World!';
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/services/hello-world/index.ts:
--------------------------------------------------------------------------------
1 | import { HelloWorldApi } from './hello-world.api';
2 | import { HelloWorldService } from './hello-world.service';
3 |
4 | export * from './hello-world.api';
5 |
6 | export const provider = {
7 | provide: HelloWorldApi,
8 | useClass: HelloWorldService,
9 | };
10 |
--------------------------------------------------------------------------------
/src/services/index.ts:
--------------------------------------------------------------------------------
1 | import { provider as helloWorldProvider } from './hello-world';
2 |
3 | export * from './hello-world';
4 |
5 | export const providers = [helloWorldProvider];
6 |
--------------------------------------------------------------------------------
/test/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { Test, TestingModule } from '@nestjs/testing';
2 | import { INestApplication } from '@nestjs/common';
3 | import * as request from 'supertest';
4 | import { AppModule } from './../src/app.module';
5 |
6 | describe('HelloWorldController (e2e)', () => {
7 | let app: INestApplication;
8 |
9 | beforeEach(async () => {
10 | const moduleFixture: TestingModule = await Test.createTestingModule({
11 | imports: [AppModule],
12 | }).compile();
13 |
14 | app = moduleFixture.createNestApplication();
15 | await app.init();
16 | });
17 |
18 | it('/ (GET)', () => {
19 | return request(app.getHttpServer())
20 | .get('/')
21 | .expect(200)
22 | .expect('Hello World!');
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/test/jest-e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "moduleFileExtensions": ["js", "json", "ts"],
3 | "rootDir": ".",
4 | "testEnvironment": "node",
5 | "testRegex": ".e2e-spec.ts$",
6 | "transform": {
7 | "^.+\\.(t|j)s$": "ts-jest"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/test/pact-verity.ts:
--------------------------------------------------------------------------------
1 | import * as path from 'path';
2 | import fs = require('fs');
3 | import {Verifier, VerifierOptions} from '@pact-foundation/pact';
4 | import * as yargs from 'yargs';
5 |
6 | import {buildApiServer} from "./helper";
7 | import * as config from '../package.json';
8 | import {ApiServer} from "../src/server";
9 | import superagent = require('superagent');
10 |
11 | const provider = config.config;
12 | const opts: VerifierOptions = config.pact as any;
13 |
14 | const argv = yargs.options({
15 | providerBaseUrl: {
16 | alias: 'p',
17 | default: `${provider.protocol}://${provider.host}:${provider.port}${provider.contextRoot}`
18 | }
19 | }).argv;
20 |
21 | const pactBrokerUrl = process.env.PACTBROKER_URL || opts.pactBrokerUrl;
22 |
23 | async function buildOptions(): Promise {
24 |
25 | const pactUrls = await listPactFiles(path.join(process.cwd(), 'pacts'));
26 | if (!pactBrokerUrl && pactUrls.length === 0) {
27 | console.log('Nothing to test. Pact Broker url not set and no pact files found');
28 | return undefined;
29 | }
30 |
31 | const options: VerifierOptions = Object.assign(
32 | {},
33 | opts,
34 | argv,
35 | pactBrokerUrl
36 | ? {pactBrokerUrl}
37 | : {pactUrls},
38 | {
39 | provider: config.name,
40 | providerVersion: config.version,
41 | publishVerificationResult: true,
42 | },
43 | );
44 |
45 | console.log('Pact verification options', options);
46 |
47 | return options;
48 | }
49 |
50 | async function listPactFiles(pactDir: string): Promise {
51 | return new Promise((resolve, reject) => {
52 | if (!fs.existsSync(pactDir)) {
53 | resolve([]);
54 | return;
55 | }
56 |
57 | fs.readdir(pactDir, (err, items) => {
58 | if (err) {
59 | reject(err);
60 | return;
61 | }
62 |
63 | if (!items || items.length == 0) {
64 | reject(new Error('no pact files found'));
65 | return;
66 | }
67 |
68 | resolve(items.map(item => path.join(pactDir, item)));
69 | });
70 | });
71 | }
72 |
73 | async function verifyPact() {
74 | const options: VerifierOptions = await buildOptions().catch(err => {
75 | console.log('Error building pact options: ' + err.message);
76 | return null;
77 | });
78 |
79 | if (!options) {
80 | return;
81 | }
82 |
83 | if (options.pactBrokerUrl) {
84 | const url = `${options.pactBrokerUrl}/pacts/provider/${options.provider}/latest`;
85 | try {
86 | await superagent.get(url);
87 | } catch (err) {
88 | if (err.status === 404) {
89 | console.log('No pacts found for provider in pact broker: ' + options.provider);
90 | return;
91 | }
92 | }
93 | }
94 |
95 | console.log('Starting server');
96 | const server: ApiServer = await buildApiServer().start();
97 |
98 | try {
99 | await new Verifier(options).verifyProvider();
100 | } finally {
101 | await server.stop();
102 | }
103 | }
104 |
105 | verifyPact().catch(err => {
106 | console.log('Error verifying provider', err);
107 | process.exit(1);
108 | });
109 |
--------------------------------------------------------------------------------
/tsconfig.build.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4 | }
5 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "declaration": true,
5 | "removeComments": true,
6 | "emitDecoratorMetadata": true,
7 | "experimentalDecorators": true,
8 | "allowSyntheticDefaultImports": true,
9 | "target": "ES2021",
10 | "sourceMap": true,
11 | "outDir": "./dist",
12 | "baseUrl": "./",
13 | "incremental": true,
14 | "skipLibCheck": true,
15 | "strictNullChecks": false,
16 | "noImplicitAny": false,
17 | "strictBindCallApply": false,
18 | "forceConsistentCasingInFileNames": false,
19 | "noFallthroughCasesInSwitch": false
20 | }
21 | }
22 |
--------------------------------------------------------------------------------