Code Monkey home page Code Monkey logo

boilerplate-typescript-rest-docker's Introduction

boilerplate-typescript-rest-docker Build Status

How to use TypeScript & Docker building a REST service with debugging enabled (e.g. WebStorm or VSCode).

Installation

# Clone the directory
$ git clone https://github.com/stefanwalther/boilerplate-typescript-rest-docker

# Install the local dependencies
# - Not necessary if you just want to use/test the docker containers

$ npm install

The Development Workflow

The development environment contains the following:

  • A docker container called rest-service containing the REST server as defined in ./src.
  • The REST services is exposed at http://localhost:8000.
  • Watcher (using nodemonhttp://nodemon.io/ ): As soon as you make changes to the ./src folder, the TypeScript files will be transpiled again and the server restarted.
    • So you can run your integration tests against your local rest-service container, which is after any change immediately up to date.
  • Remote debugging enabled through port 5858.

Run the Development Environment

$ docker-compose --f=./docker/docker-compose.dev.yml up

This will give you all of the above described.

Debugging in WebStorm

Assuming that rest-service itself could rely on other services it makes sense just to spin up the development environment:

$ docker-compose --f=./docker/docker-compose.dev.yml up

So you can run your integration tests against http://localhost8000 The rest-service will be updated every time you make updates to the ./src folder.

If you want to debug the rest-service (e.g. when hitting integration tests against the rest-service) this is the configuration being used in this example:

Create a remote debugger

  • ./docker/docker-compose.dev.yml opens the port 5858 for the debugger, so let's connect to it:

Remote Debugger Configuration in WebStorm

Running Unit Tests

Running the unit test in this scenario is straight-forward, just configure WebStorm as follows. (This will not use the container, just directly test the transpiled TypeScript code).

Configure Unit Tests in WebStorm

Most of the settings should be default, except:

  • Extra mocha options: --require ./test/mocha.conf.js
  • Test file patterns: ./test/unit/**/*.spec.ts

Hit the Debugger (That's the trick!!!)

If you want to debug the rest-service (running inside the container), follow these steps:

1) Set up the remote debugger as shown above
2) Run the development environment docker-compose --f=./docker/docker-compose.dev.yml up

3) Set up the integration tests in Mocha:

The configuration is very similar to the unit tests:

Configure Integration Tests in WebStorm

  • Extra mocha options: --require ./test/mocha.conf.js
  • Test file patterns: ./test/integration/**/*.spec.ts

4) Start your "Remote Debugger"

Start Remote Debugger in WebStorm

Here come the trick. If you don't see your ./*.ts files (as in the screenshot below), then the sourcemaps as created by tsc have not been resolved by WebStorm. (That's a bug and I'll file it as such).

Watch the Tool's Panel in WebStorm

There's a neat trick, though a bit annoying, but i works:

Just press the "Re-Run Debugger" icon, and then you should see the ./*.ts files as in the second following screenshot.

Watch the Tool's Panel  in WebStorm

Watch the Tool's Panel  in WebStorm

Once this works you can hit any breakpoint in the rest-service (e.g. by running test:integration in Run mode) and it will be hit:

Debugging WebStorm

Continuous Integration

To simulate the Continuous Integration script run the following

$ bash ./docker/docker-ci.sh

An example how to implement CI using travis is provided, have a look at the .travis.yml file and the result .

Credits

This solutions is very much inspired by the following two articles:

Another very interesting read in that context:

boilerplate-typescript-rest-docker's People

Contributors

renovate-bot avatar renovate[bot] avatar stefanwalther avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

boilerplate-typescript-rest-docker's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm supertest-as-promised Unavailable
npm tslint Unavailable
npm tslint-microsoft-contrib Unavailable

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency chai to v5
  • chore(deps): update dependency mocha to v10 (mocha, @types/mocha)
  • chore(deps): update dependency supertest to v7
  • chore(deps): update dependency tslint to v6
  • chore(deps): update dependency typescript to v5
  • chore(deps): update node.js to v20 (node, @types/node)
  • 🔐 Create all rate-limited PRs at once 🔐

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker/docker-compose.ci.yml
docker/docker-compose.dev.yml
docker/rest-service-integration/docker-compose.yml
docker/rest-service/docker-compose.yml
dockerfile
docker/rest-service-integration/Dockerfile
  • node 6.9.1
docker/rest-service/Dockerfile
  • node 6.9.1
npm
package.json
  • @types/body-parser 0.0.33
  • @types/chai ^3.4.34
  • @types/express ^4.0.33
  • @types/mocha ^2.2.32
  • @types/node ^6.0.46
  • @types/supertest ^1.1.31
  • @types/supertest-as-promised ^2.0.32
  • body-parser ^1.15.2
  • express ^4.14.0
  • install ^0.8.2
  • npm ^3.10.9
  • chai 3.5.0
  • mocha 3.5.3
  • promise-retry 1.1.1
  • supertest 2.0.1
  • supertest-as-promised 4.0.2
  • ts-node 1.7.3
  • tslint 3.15.1
  • tslint-microsoft-contrib 2.0.14
  • typescript 2.9.2

  • Check this box to trigger a request for Renovate to run again on this repository

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Cannot run or build in Node 8 enviornment

I am having trouble to get the current implementation to run in the following environments:

  • Host (Node 8/9), TypeScript fails to build correctly
  • Docker fails to run, further investigation shows that the culprit is TypeScript

I have created a pull request #4 that addresses the issue above.

Dependency deprecation warning: supertest-as-promised (npm)

On registry https://registry.npmjs.org/, the "latest" version (v4.0.2) of dependency supertest-as-promised has the following deprecation notice:

SuperTest 2.0+ supports promises natively; use that instead!

Marking the latest version of an npm package as deprecated results in the entire package being considered deprecated, so contact the package author you think this is a mistake.

Affected package file(s): package.json

If you don't care about this, you can close this issue and not be warned about supertest-as-promised's deprecation again. If you would like to completely disable all future deprecation warnings then add the following to your config:

"suppressNotifications": ["deprecationWarningIssues"]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.