├── Chapter02 ├── first-microservice │ ├── .dockerignore │ ├── .vscode │ │ └── launch.json │ ├── Dockerfile │ ├── dist │ │ ├── common │ │ │ ├── logging.js │ │ │ └── logging.js.map │ │ ├── config │ │ │ ├── Application.js │ │ │ ├── Application.js.map │ │ │ ├── Express.js │ │ │ └── Express.js.map │ │ ├── controllers │ │ │ ├── HelloWorld.js │ │ │ └── HelloWorld.js.map │ │ ├── index.js │ │ └── index.js.map │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ └── index.ts │ └── tsconfig.json ├── handing-asynchronous-nature │ ├── dist │ │ ├── async_await_example.js │ │ ├── async_await_example.js.map │ │ ├── multiple_parallel.js │ │ ├── multiple_parallel.js.map │ │ ├── retry_failed_req.js │ │ ├── retry_failed_req.js.map │ │ ├── yield.js │ │ └── yield.js.map │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── async_await_example.ts │ │ ├── multiple_parallel.ts │ │ └── retry_failed_req.ts │ └── tsconfig.json ├── node-clusters │ ├── .vscode │ │ └── launch.json │ ├── dist │ │ ├── app.js │ │ ├── app.js.map │ │ └── bin │ │ │ ├── www.js │ │ │ └── www.js.map │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── app.ts │ │ └── bin │ │ │ └── www.ts │ └── tsconfig.json └── node-streams │ ├── dist │ ├── filter_stream.js │ ├── filter_stream.js.map │ ├── stream_test.js │ └── stream_test.js.map │ ├── package-lock.json │ ├── package.json │ ├── src │ ├── filter_stream.ts │ └── stream_test.ts │ └── tsconfig.json ├── Chapter03 ├── using_baconjs │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloBacon.ts │ │ ├── index.ts │ │ └── services │ │ │ └── BaconService.ts │ └── tsconfig.json ├── using_highlandjs │ ├── file1.txt │ ├── file2.txt │ ├── file3.txt │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json └── using_rxjs │ ├── package-lock.json │ ├── package.json │ ├── src │ ├── rx_combinations.ts │ ├── rx_error_handling.ts │ └── rx_filtering.ts │ └── tsconfig.json ├── Chapter04 ├── products-catalog -with-docker │ ├── .vscode │ │ └── launch.json │ ├── Dockerfile │ ├── config │ │ └── default.json │ ├── docker-compose.yml │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── Index.ts │ │ ├── business-layer │ │ │ └── validator │ │ │ │ ├── ProductValidationProcessor.ts │ │ │ │ └── ProductValidationSchema.ts │ │ ├── data-layer │ │ │ ├── adapters │ │ │ │ └── MongoAccess.ts │ │ │ ├── data-abstracts │ │ │ │ └── repositories │ │ │ │ │ ├── IProductDocument.ts │ │ │ │ │ ├── ProductRepository.ts │ │ │ │ │ ├── ProductSchema.ts │ │ │ │ │ └── index.ts │ │ │ ├── data-agents │ │ │ │ └── ProductDataAgent.ts │ │ │ └── models │ │ │ │ └── ProductModel.ts │ │ ├── middleware │ │ │ ├── common │ │ │ │ └── Logging.ts │ │ │ ├── config │ │ │ │ ├── Application.ts │ │ │ │ └── Express.ts │ │ │ └── custom-middleware │ │ │ │ └── MyMiddleWare.ts │ │ └── service-layer │ │ │ ├── controllers │ │ │ └── ProductsController.ts │ │ │ ├── request │ │ │ └── IProductRequest.ts │ │ │ └── responses │ │ │ └── IProductResponse.ts │ └── tsconfig.json └── products-catalog │ ├── .vscode │ └── launch.json │ ├── Dockerfile │ ├── config │ └── default.json │ ├── docker-compose.yml │ ├── package-lock.json │ ├── package.json │ ├── src │ ├── Index.ts │ ├── business-layer │ │ └── validator │ │ │ ├── ProductValidationProcessor.ts │ │ │ └── ProductValidationSchema.ts │ ├── data-layer │ │ ├── adapters │ │ │ └── MongoAccess.ts │ │ ├── data-abstracts │ │ │ └── repositories │ │ │ │ ├── IProductDocument.ts │ │ │ │ ├── ProductRepository.ts │ │ │ │ ├── ProductSchema.ts │ │ │ │ └── index.ts │ │ ├── data-agents │ │ │ └── ProductDataAgent.ts │ │ └── models │ │ │ └── ProductModel.ts │ ├── middleware │ │ ├── common │ │ │ └── Logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ └── custom-middleware │ │ │ └── MyMiddleWare.ts │ └── service-layer │ │ ├── controllers │ │ └── ProductsController.ts │ │ ├── request │ │ └── IProductRequest.ts │ │ └── responses │ │ └── IProductResponse.ts │ └── tsconfig.json ├── Chapter05 ├── api_gateway │ └── package.json └── hystrix_example │ └── app.js ├── Chapter06 ├── consul │ └── consul-producer │ │ ├── .vscode │ │ └── launch.json │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ ├── custom_types │ │ │ └── consul.d.ts │ │ └── index.ts │ │ └── tsconfig.json └── eureka │ ├── eureka-server │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── microservices │ │ │ │ └── demo │ │ │ │ └── discovery │ │ │ │ └── demoservicediscovery │ │ │ │ └── DemoServiceDiscoveryApplication.java │ │ └── resources │ │ │ └── bootstrap.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── microservices │ │ └── demo │ │ └── discovery │ │ └── demoservicediscovery │ │ └── DemoServiceDiscoveryApplicationTests.java │ ├── eureka-service-discovery │ ├── .vscode │ │ └── launch.json │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ ├── EurekaService.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ ├── custom_types │ │ │ └── eureka-js-client.d.ts │ │ └── index.ts │ └── tsconfig.json │ └── first-microservice-register │ ├── .dockerignore │ ├── .vscode │ └── launch.json │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ ├── common │ │ └── logging.ts │ ├── config │ │ ├── Application.ts │ │ └── Express.ts │ ├── controllers │ │ └── HelloWorld.ts │ ├── custom_types │ │ └── eureka-js-client.d.ts │ └── index.ts │ └── tsconfig.json ├── Chapter07 ├── bit-code-sharing │ ├── consumer │ │ ├── .bitmap │ │ ├── package-lock.json │ │ └── package.json │ └── demo-microservice │ │ ├── .bitmap │ │ ├── Dockerfile │ │ ├── bit.json │ │ ├── hello world │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── src │ │ ├── common │ │ │ ├── cacheReader.ts │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ ├── index.ts │ │ └── tests │ │ │ ├── cacheReader.spec.ts │ │ │ └── logging.spec.ts │ │ └── tsconfig.json ├── http2 │ ├── README.md │ ├── certs │ │ ├── server.crt │ │ ├── server.csr │ │ └── server.key │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ └── index.ts │ └── tsconfig.json ├── hystrix │ ├── .dockerignore │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ ├── Express.ts │ │ │ └── HystrixStream.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ ├── custom_types │ │ │ └── opossum.d.ts │ │ └── index.ts │ └── tsconfig.json ├── kafka │ └── node-producer │ │ ├── .vscode │ │ └── launch.json │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── src │ │ ├── app.ts │ │ └── consumer.ts │ │ └── tsconfig.json ├── netflix cloud │ ├── eureka-server │ │ ├── .gitignore │ │ ├── mvnw │ │ ├── mvnw.cmd │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── microservices │ │ │ └── demo │ │ │ └── discovery │ │ │ └── demoservicediscovery │ │ │ └── DemoServiceDiscoveryApplication.java │ ├── first-microservice-register-node │ │ ├── .dockerignore │ │ ├── .vscode │ │ │ └── launch.json │ │ ├── Dockerfile │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── src │ │ │ ├── common │ │ │ │ └── logging.ts │ │ │ ├── config │ │ │ │ ├── Application.ts │ │ │ │ └── Express.ts │ │ │ ├── controllers │ │ │ │ └── HelloWorld.ts │ │ │ ├── custom_types │ │ │ │ └── eureka-js-client.d.ts │ │ │ └── index.ts │ │ └── tsconfig.json │ ├── java-microservice │ │ ├── .gitignore │ │ ├── mvnw │ │ ├── mvnw.cmd │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── polyglot │ │ │ └── java │ │ │ └── javamicroservice │ │ │ ├── JavaMicroserviceApplication.java │ │ │ ├── model │ │ │ └── ProductModel.java │ │ │ └── service │ │ │ └── DemoController.java │ └── zuuul-server │ │ ├── .gitignore │ │ ├── mvnw │ │ ├── mvnw.cmd │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── microservices │ │ └── demo │ │ └── discovery │ │ └── netflixosss │ │ └── NetflixOsssApplication.java ├── standalone-hystrix-dashboard-all.jar └── thrift-rpc │ ├── package-lock.json │ ├── package.json │ ├── src │ ├── codegen │ │ └── com │ │ │ ├── popularity │ │ │ └── PopularityService.ts │ │ │ └── product │ │ │ └── ProductService.ts │ ├── config │ │ └── default.ts │ ├── gateway │ │ └── server.ts │ ├── index.ts │ ├── popularity │ │ ├── data.ts │ │ └── server.ts │ └── product │ │ ├── data.ts │ │ └── server.ts │ ├── thrift │ ├── popularity │ │ └── PopularityService.thrift │ └── product │ │ └── ProductService.thrift │ └── tsconfig.json ├── Chapter08 ├── bottom-up-swagger │ ├── .vscode │ │ └── launch.json │ ├── Dockerfile │ ├── config │ │ └── default.json │ ├── docker-compose.yml │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── Index.ts │ │ ├── business-layer │ │ │ └── validator │ │ │ │ ├── ProductValidationProcessor.ts │ │ │ │ └── ProductValidationSchema.ts │ │ ├── data-layer │ │ │ ├── adapters │ │ │ │ └── MongoAccess.ts │ │ │ ├── data-abstracts │ │ │ │ └── repositories │ │ │ │ │ ├── IProductDocument.ts │ │ │ │ │ ├── ProductRepository.ts │ │ │ │ │ ├── ProductSchema.ts │ │ │ │ │ └── index.ts │ │ │ ├── data-agents │ │ │ │ └── ProductDataAgent.ts │ │ │ └── models │ │ │ │ └── ProductModel.ts │ │ ├── middleware │ │ │ ├── common │ │ │ │ └── Logging.ts │ │ │ ├── config │ │ │ │ ├── Application.ts │ │ │ │ └── Express.ts │ │ │ └── custom-middleware │ │ │ │ └── MyMiddleWare.ts │ │ └── service-layer │ │ │ ├── controllers │ │ │ ├── ProductsController.ts │ │ │ └── SwaggerController.ts │ │ │ ├── request │ │ │ └── IProductRequest.ts │ │ │ └── responses │ │ │ └── IProductResponse.ts │ └── tsconfig.json ├── cpu-profiling-demo │ ├── .vscode │ │ └── launch.json │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── app.ts │ │ └── bin │ │ │ └── www.ts │ └── tsconfig.json ├── heapdump_demo │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ └── index.ts │ └── tsconfig.json ├── hello_world_swagger.yaml ├── products-catalog │ ├── .vscode │ │ └── launch.json │ ├── Dockerfile │ ├── config │ │ └── default.json │ ├── docker-compose.yml │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── Index.ts │ │ ├── business-layer │ │ │ └── validator │ │ │ │ ├── ProductValidationProcessor.ts │ │ │ │ └── ProductValidationSchema.ts │ │ ├── data-layer │ │ │ ├── adapters │ │ │ │ └── MongoAccess.ts │ │ │ ├── data-abstracts │ │ │ │ └── repositories │ │ │ │ │ ├── IProductDocument.ts │ │ │ │ │ ├── ProductRepository.ts │ │ │ │ │ ├── ProductSchema.ts │ │ │ │ │ └── index.ts │ │ │ ├── data-agents │ │ │ │ └── ProductDataAgent.ts │ │ │ └── models │ │ │ │ └── ProductModel.ts │ │ ├── middleware │ │ │ ├── common │ │ │ │ └── Logging.ts │ │ │ ├── config │ │ │ │ ├── Application.ts │ │ │ │ └── Express.ts │ │ │ └── custom-middleware │ │ │ │ └── MyMiddleWare.ts │ │ └── service-layer │ │ │ ├── controllers │ │ │ └── ProductsController.ts │ │ │ ├── request │ │ │ └── IProductRequest.ts │ │ │ └── responses │ │ │ └── IProductResponse.ts │ └── tsconfig.json ├── swagger-code-gen │ ├── hello_world_swagger.yaml │ ├── swagger-codegen-master │ │ ├── .dockerignore │ │ ├── .gitignore │ │ ├── .java-version │ │ ├── .travis.yml │ │ ├── .travis.yml.bash │ │ ├── .travis.yml.ios │ │ ├── CODE_OF_CONDUCT.md │ │ ├── CONTRIBUTING.md │ │ ├── Dockerfile │ │ ├── LICENSE │ │ ├── README.md │ │ ├── Vagrantfile │ │ ├── appveyor.yml │ │ ├── circle.yml │ │ ├── docker-entrypoint.sh │ │ ├── eclipse-formatter.xml │ │ ├── google_checkstyle.xml │ │ ├── modules │ │ │ ├── swagger-codegen-cli │ │ │ │ ├── Dockerfile │ │ │ │ ├── pom.xml │ │ │ │ └── src │ │ │ │ │ └── main │ │ │ │ │ └── java │ │ │ │ │ └── io │ │ │ │ │ └── swagger │ │ │ │ │ └── codegen │ │ │ │ │ ├── SwaggerCodegen.java │ │ │ │ │ └── cmd │ │ │ │ │ ├── ConfigHelp.java │ │ │ │ │ ├── Generate.java │ │ │ │ │ ├── Langs.java │ │ │ │ │ ├── Meta.java │ │ │ │ │ ├── Validate.java │ │ │ │ │ ├── ValidateException.java │ │ │ │ │ └── Version.java │ │ │ ├── swagger-codegen-maven-plugin │ │ │ │ ├── README.md │ │ │ │ ├── examples │ │ │ │ │ ├── java-client.xml │ │ │ │ │ └── swagger.yaml │ │ │ │ ├── pom.xml │ │ │ │ └── src │ │ │ │ │ └── main │ │ │ │ │ └── java │ │ │ │ │ └── io │ │ │ │ │ └── swagger │ │ │ │ │ └── codegen │ │ │ │ │ └── plugin │ │ │ │ │ └── CodeGenMojo.java │ │ │ ├── swagger-codegen │ │ │ │ ├── .gitignore │ │ │ │ ├── pom.xml │ │ │ │ └── src │ │ │ │ │ └── main │ │ │ │ │ └── java │ │ │ │ │ ├── config │ │ │ │ │ ├── Config.java │ │ │ │ │ └── ConfigParser.java │ │ │ │ │ └── io │ │ │ │ │ └── swagger │ │ │ │ │ └── codegen │ │ │ │ │ ├── AbstractGenerator.java │ │ │ │ │ ├── CliOption.java │ │ │ │ │ ├── ClientOptInput.java │ │ │ │ │ ├── ClientOpts.java │ │ │ │ │ ├── Codegen.java │ │ │ │ │ ├── CodegenConfig.java │ │ │ │ │ ├── CodegenConfigLoader.java │ │ │ │ │ ├── CodegenConstants.java │ │ │ │ │ ├── CodegenModel.java │ │ │ │ │ ├── CodegenModelFactory.java │ │ │ │ │ ├── CodegenModelType.java │ │ │ │ │ ├── CodegenOperation.java │ │ │ │ │ ├── CodegenParameter.java │ │ │ │ │ ├── CodegenProperty.java │ │ │ │ │ ├── CodegenResponse.java │ │ │ │ │ ├── CodegenSecurity.java │ │ │ │ │ ├── CodegenType.java │ │ │ │ │ ├── DefaultCodegen.java │ │ │ │ │ ├── DefaultGenerator.java │ │ │ │ │ ├── Generator.java │ │ │ │ │ ├── GlobalSupportingFile.java │ │ │ │ │ ├── InlineModelResolver.java │ │ │ │ │ ├── MetaGenerator.java │ │ │ │ │ ├── SupportingFile.java │ │ │ │ │ ├── auth │ │ │ │ │ ├── AuthMethod.java │ │ │ │ │ └── AuthParser.java │ │ │ │ │ ├── config │ │ │ │ │ ├── CodegenConfigurator.java │ │ │ │ │ └── CodegenConfiguratorUtils.java │ │ │ │ │ ├── examples │ │ │ │ │ ├── ExampleGenerator.java │ │ │ │ │ └── XmlExampleGenerator.java │ │ │ │ │ ├── ignore │ │ │ │ │ ├── CodegenIgnoreProcessor.java │ │ │ │ │ └── rules │ │ │ │ │ │ ├── DirectoryRule.java │ │ │ │ │ │ ├── EverythingRule.java │ │ │ │ │ │ ├── FileRule.java │ │ │ │ │ │ ├── IgnoreLineParser.java │ │ │ │ │ │ ├── InvalidRule.java │ │ │ │ │ │ ├── ParserException.java │ │ │ │ │ │ ├── Part.java │ │ │ │ │ │ ├── RootedFileRule.java │ │ │ │ │ │ └── Rule.java │ │ │ │ │ ├── languages │ │ │ │ │ ├── AbstractAdaCodegen.java │ │ │ │ │ ├── AbstractCSharpCodegen.java │ │ │ │ │ ├── AbstractCppCodegen.java │ │ │ │ │ ├── AbstractEiffelCodegen.java │ │ │ │ │ ├── AbstractGoCodegen.java │ │ │ │ │ ├── AbstractJavaCodegen.java │ │ │ │ │ ├── AbstractJavaJAXRSServerCodegen.java │ │ │ │ │ ├── AbstractKotlinCodegen.java │ │ │ │ │ ├── AbstractPhpCodegen.java │ │ │ │ │ ├── AbstractScalaCodegen.java │ │ │ │ │ ├── AbstractTypeScriptClientCodegen.java │ │ │ │ │ ├── AdaCodegen.java │ │ │ │ │ ├── AdaServerCodegen.java │ │ │ │ │ ├── AkkaScalaClientCodegen.java │ │ │ │ │ ├── AndroidClientCodegen.java │ │ │ │ │ ├── Apache2ConfigCodegen.java │ │ │ │ │ ├── ApexClientCodegen.java │ │ │ │ │ ├── AspNetCoreServerCodegen.java │ │ │ │ │ ├── BashClientCodegen.java │ │ │ │ │ ├── CSharpClientCodegen.java │ │ │ │ │ ├── ClojureClientCodegen.java │ │ │ │ │ ├── ConfluenceWikiGenerator.java │ │ │ │ │ ├── CppRestClientCodegen.java │ │ │ │ │ ├── CsharpDotNet2ClientCodegen.java │ │ │ │ │ ├── DartClientCodegen.java │ │ │ │ │ ├── EiffelClientCodegen.java │ │ │ │ │ ├── ElixirClientCodegen.java │ │ │ │ │ ├── ElmClientCodegen.java │ │ │ │ │ ├── ErlangClientCodegen.java │ │ │ │ │ ├── ErlangServerCodegen.java │ │ │ │ │ ├── FinchServerCodegen.java │ │ │ │ │ ├── FlashClientCodegen.java │ │ │ │ │ ├── FlaskConnexionCodegen.java │ │ │ │ │ ├── GoClientCodegen.java │ │ │ │ │ ├── GoServerCodegen.java │ │ │ │ │ ├── GroovyClientCodegen.java │ │ │ │ │ ├── HaskellHttpClientCodegen.java │ │ │ │ │ ├── HaskellServantCodegen.java │ │ │ │ │ ├── JMeterCodegen.java │ │ │ │ │ ├── JavaCXFClientCodegen.java │ │ │ │ │ ├── JavaCXFServerCodegen.java │ │ │ │ │ ├── JavaClientCodegen.java │ │ │ │ │ ├── JavaInflectorServerCodegen.java │ │ │ │ │ ├── JavaJAXRSCXFCDIServerCodegen.java │ │ │ │ │ ├── JavaJAXRSSpecServerCodegen.java │ │ │ │ │ ├── JavaJerseyServerCodegen.java │ │ │ │ │ ├── JavaMSF4JServerCodegen.java │ │ │ │ │ ├── JavaPKMSTServerCodegen.java │ │ │ │ │ ├── JavaPlayFrameworkCodegen.java │ │ │ │ │ ├── JavaResteasyEapServerCodegen.java │ │ │ │ │ ├── JavaResteasyServerCodegen.java │ │ │ │ │ ├── JavaVertXServerCodegen.java │ │ │ │ │ ├── JavascriptClientCodegen.java │ │ │ │ │ ├── JavascriptClosureAngularClientCodegen.java │ │ │ │ │ ├── KotlinClientCodegen.java │ │ │ │ │ ├── KotlinServerCodegen.java │ │ │ │ │ ├── LuaClientCodegen.java │ │ │ │ │ ├── LumenServerCodegen.java │ │ │ │ │ ├── NancyFXServerCodegen.java │ │ │ │ │ ├── NodeJSServerCodegen.java │ │ │ │ │ ├── ObjcClientCodegen.java │ │ │ │ │ ├── PerlClientCodegen.java │ │ │ │ │ ├── PhpClientCodegen.java │ │ │ │ │ ├── PistacheServerCodegen.java │ │ │ │ │ ├── PowerShellClientCodegen.java │ │ │ │ │ ├── PythonClientCodegen.java │ │ │ │ │ ├── Qt5CPPGenerator.java │ │ │ │ │ ├── RClientCodegen.java │ │ │ │ │ ├── Rails5ServerCodegen.java │ │ │ │ │ ├── RestbedCodegen.java │ │ │ │ │ ├── RubyClientCodegen.java │ │ │ │ │ ├── RustClientCodegen.java │ │ │ │ │ ├── RustServerCodegen.java │ │ │ │ │ ├── ScalaClientCodegen.java │ │ │ │ │ ├── ScalaGatlingCodegen.java │ │ │ │ │ ├── ScalaLagomServerCodegen.java │ │ │ │ │ ├── ScalatraServerCodegen.java │ │ │ │ │ ├── ScalazClientCodegen.java │ │ │ │ │ ├── SilexServerCodegen.java │ │ │ │ │ ├── SinatraServerCodegen.java │ │ │ │ │ ├── SlimFrameworkServerCodegen.java │ │ │ │ │ ├── SpringCodegen.java │ │ │ │ │ ├── StaticDocCodegen.java │ │ │ │ │ ├── StaticHtml2Generator.java │ │ │ │ │ ├── StaticHtmlGenerator.java │ │ │ │ │ ├── SwaggerGenerator.java │ │ │ │ │ ├── SwaggerYamlGenerator.java │ │ │ │ │ ├── Swift3Codegen.java │ │ │ │ │ ├── Swift4Codegen.java │ │ │ │ │ ├── SwiftCodegen.java │ │ │ │ │ ├── SymfonyServerCodegen.java │ │ │ │ │ ├── TizenClientCodegen.java │ │ │ │ │ ├── TypeScriptAngularClientCodegen.java │ │ │ │ │ ├── TypeScriptAngularJsClientCodegen.java │ │ │ │ │ ├── TypeScriptAureliaClientCodegen.java │ │ │ │ │ ├── TypeScriptFetchClientCodegen.java │ │ │ │ │ ├── TypeScriptInversifyClientCodegen.java │ │ │ │ │ ├── TypeScriptJqueryClientCodegen.java │ │ │ │ │ ├── TypeScriptNodeClientCodegen.java │ │ │ │ │ ├── UndertowCodegen.java │ │ │ │ │ ├── ZendExpressivePathHandlerServerCodegen.java │ │ │ │ │ └── features │ │ │ │ │ │ ├── BeanValidationExtendedFeatures.java │ │ │ │ │ │ ├── BeanValidationFeatures.java │ │ │ │ │ │ ├── CXFFeatures.java │ │ │ │ │ │ ├── CXFServerFeatures.java │ │ │ │ │ │ ├── GzipFeatures.java │ │ │ │ │ │ ├── GzipTestFeatures.java │ │ │ │ │ │ ├── JbossFeature.java │ │ │ │ │ │ ├── LoggingFeatures.java │ │ │ │ │ │ ├── LoggingTestFeatures.java │ │ │ │ │ │ ├── OptionalFeatures.java │ │ │ │ │ │ ├── PerformBeanValidationFeatures.java │ │ │ │ │ │ ├── SpringFeatures.java │ │ │ │ │ │ ├── SwaggerFeatures.java │ │ │ │ │ │ ├── SwaggerUIFeatures.java │ │ │ │ │ │ └── UseGenericResponseFeatures.java │ │ │ │ │ ├── mustache │ │ │ │ │ ├── CamelCaseLambda.java │ │ │ │ │ ├── IndentedLambda.java │ │ │ │ │ ├── LowercaseLambda.java │ │ │ │ │ ├── TitlecaseLambda.java │ │ │ │ │ └── UppercaseLambda.java │ │ │ │ │ └── utils │ │ │ │ │ ├── ImplementationVersion.java │ │ │ │ │ ├── Markdown.java │ │ │ │ │ ├── ModelUtils.java │ │ │ │ │ ├── OptionUtils.java │ │ │ │ │ └── SemVer.java │ │ │ └── swagger-generator │ │ │ │ ├── Dockerfile │ │ │ │ ├── pom.xml │ │ │ │ ├── sample.json │ │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── java │ │ │ │ └── io │ │ │ │ │ └── swagger │ │ │ │ │ └── generator │ │ │ │ │ ├── Bootstrap.java │ │ │ │ │ ├── DynamicSwaggerConfig.java │ │ │ │ │ ├── exception │ │ │ │ │ ├── ApiException.java │ │ │ │ │ ├── BadRequestException.java │ │ │ │ │ └── NotFoundException.java │ │ │ │ │ ├── model │ │ │ │ │ ├── ApiResponse.java │ │ │ │ │ ├── Generated.java │ │ │ │ │ ├── GeneratorInput.java │ │ │ │ │ ├── InputOption.java │ │ │ │ │ └── ResponseCode.java │ │ │ │ │ ├── online │ │ │ │ │ └── Generator.java │ │ │ │ │ ├── resource │ │ │ │ │ ├── ExceptionWriter.java │ │ │ │ │ └── SwaggerResource.java │ │ │ │ │ └── util │ │ │ │ │ ├── ApiOriginFilter.java │ │ │ │ │ ├── JacksonJsonProvider.java │ │ │ │ │ ├── ValidationException.java │ │ │ │ │ ├── ValidationMessage.java │ │ │ │ │ └── ZipUtil.java │ │ │ │ └── webapp │ │ │ │ ├── WEB-INF │ │ │ │ └── web.xml │ │ │ │ └── index.html │ │ ├── mvnw │ │ ├── mvnw.cmd │ │ ├── new.sh │ │ ├── pom.xml │ │ ├── pom.xml.bash │ │ ├── pom.xml.circleci │ │ ├── pom.xml.circleci.java7 │ │ ├── pom.xml.ios │ │ ├── pom.xml.shippable │ │ ├── run-in-docker.sh │ │ └── shippable.yml │ └── typescript-nodejs │ │ ├── .gitignore │ │ ├── .swagger-codegen-ignore │ │ ├── .swagger-codegen │ │ └── VERSION │ │ ├── api.ts │ │ └── git_push.sh ├── top-down-swagger │ ├── package-lock.json │ └── package.json ├── ts-http-proxy │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── index.ts │ └── tsconfig.json └── typescript-node-client │ ├── .gitignore │ ├── .swagger-codegen-ignore │ ├── .swagger-codegen │ └── VERSION │ ├── api.ts │ └── git_push.sh ├── Chapter09 ├── Nginx-node-mongo │ ├── Dockerfile │ ├── config │ │ └── default.json │ ├── docker-compose.yml │ ├── nginx │ │ ├── Dockerfile │ │ ├── certs │ │ │ ├── server.crt │ │ │ ├── server.csr │ │ │ └── server.key │ │ ├── nginx.conf │ │ └── sites-enabled │ │ │ └── nodejs_project │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── Index.ts │ │ ├── business-layer │ │ │ └── validator │ │ │ │ ├── ProductValidationProcessor.ts │ │ │ │ └── ProductValidationSchema.ts │ │ ├── data-layer │ │ │ ├── adapters │ │ │ │ └── MongoAccess.ts │ │ │ ├── data-abstracts │ │ │ │ └── repositories │ │ │ │ │ ├── IProductDocument.ts │ │ │ │ │ ├── ProductRepository.ts │ │ │ │ │ ├── ProductSchema.ts │ │ │ │ │ └── index.ts │ │ │ ├── data-agents │ │ │ │ └── ProductDataAgent.ts │ │ │ └── models │ │ │ │ └── ProductModel.ts │ │ ├── middleware │ │ │ ├── common │ │ │ │ └── Logging.ts │ │ │ ├── config │ │ │ │ ├── Application.ts │ │ │ │ └── Express.ts │ │ │ └── custom-middleware │ │ │ │ └── MyMiddleWare.ts │ │ └── service-layer │ │ │ ├── controllers │ │ │ └── ProductsController.ts │ │ │ ├── request │ │ │ └── IProductRequest.ts │ │ │ └── responses │ │ │ └── IProductResponse.ts │ └── tsconfig.json ├── counter-metric │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ ├── CounterMiddleware.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ ├── index.ts │ │ └── types.ts │ └── tsconfig.json ├── elk-logz.io │ ├── Dockerfile │ ├── config │ │ └── default.json │ ├── docker-compose.yml │ ├── my-logs-file.txt │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── Index.ts │ │ ├── business-layer │ │ │ └── validator │ │ │ │ ├── ProductValidationProcessor.ts │ │ │ │ └── ProductValidationSchema.ts │ │ ├── custom_types │ │ │ └── winston-logzio.d.ts │ │ ├── data-layer │ │ │ ├── adapters │ │ │ │ └── MongoAccess.ts │ │ │ ├── data-abstracts │ │ │ │ └── repositories │ │ │ │ │ ├── IProductDocument.ts │ │ │ │ │ ├── ProductRepository.ts │ │ │ │ │ ├── ProductSchema.ts │ │ │ │ │ └── index.ts │ │ │ ├── data-agents │ │ │ │ └── ProductDataAgent.ts │ │ │ └── models │ │ │ │ └── ProductModel.ts │ │ ├── middleware │ │ │ ├── common │ │ │ │ ├── LogConfig.ts │ │ │ │ └── Logging.ts │ │ │ ├── config │ │ │ │ ├── Application.ts │ │ │ │ └── Express.ts │ │ │ └── custom-middleware │ │ │ │ └── MyMiddleWare.ts │ │ └── service-layer │ │ │ ├── controllers │ │ │ └── ProductsController.ts │ │ │ ├── request │ │ │ └── IProductRequest.ts │ │ │ └── responses │ │ │ └── IProductResponse.ts │ └── tsconfig.json ├── logstash-simple.conf ├── meter metric │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ ├── index.ts │ │ └── types.ts │ └── tsconfig.json ├── pmx-utilities │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ ├── index.ts │ │ └── types.ts │ └── tsconfig.json ├── prometheus-grafana │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── prometheus-data │ │ ├── alert.rules │ │ └── prometheus.yml │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── AfterMiddleware.ts │ │ │ ├── Application.ts │ │ │ ├── Express.ts │ │ │ └── metrics-modules │ │ │ │ └── MetricModule.ts │ │ ├── controllers │ │ │ ├── DemoRoute1.ts │ │ │ ├── HelloWorld.ts │ │ │ └── MetricsRoute.ts │ │ ├── index.ts │ │ └── types.ts │ └── tsconfig.json ├── simple-metric │ ├── .dockerignore │ ├── .vscode │ │ └── launch.json │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── simple-metric.rar │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ ├── index.ts │ │ └── types.ts │ └── tsconfig.json ├── user │ ├── .dockerignore │ ├── .vscode │ │ └── launch.json │ ├── Dockerfile │ ├── first-microservice.rar │ ├── first-microservice.rar.txt │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── UserController.ts │ │ └── index.ts │ └── tsconfig.json └── zipkin │ ├── .vscode │ └── launch.json │ ├── config │ └── default.json │ ├── package-lock.json │ ├── package.json │ ├── server │ └── zipkin-server-2.7.1-exec.jar │ ├── src │ ├── Index.ts │ ├── business-layer │ │ └── validator │ │ │ ├── ProductValidationProcessor.ts │ │ │ └── ProductValidationSchema.ts │ ├── data-layer │ │ ├── adapters │ │ │ └── MongoAccess.ts │ │ ├── data-abstracts │ │ │ └── repositories │ │ │ │ ├── IProductDocument.ts │ │ │ │ ├── ProductRepository.ts │ │ │ │ ├── ProductSchema.ts │ │ │ │ └── index.ts │ │ ├── data-agents │ │ │ └── ProductDataAgent.ts │ │ └── models │ │ │ └── ProductModel.ts │ ├── middleware │ │ ├── common │ │ │ └── Logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ ├── Express.ts │ │ │ └── ZipkinConfig.ts │ │ └── custom-middleware │ │ │ └── MyMiddleWare.ts │ └── service-layer │ │ ├── controllers │ │ └── ProductsController.ts │ │ ├── request │ │ └── IProductRequest.ts │ │ └── responses │ │ └── IProductResponse.ts │ └── tsconfig.json ├── Chapter10 ├── auditjs │ ├── .dockerignore │ ├── .vscode │ │ └── launch.json │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ └── index.ts │ └── tsconfig.json ├── express-lusca │ ├── .dockerignore │ ├── .vscode │ │ └── launch.json │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ └── index.ts │ └── tsconfig.json ├── rate-limiter │ ├── .dockerignore │ ├── .vscode │ │ └── launch.json │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ └── index.ts │ └── tsconfig.json ├── safe-regex │ ├── package-lock.json │ └── safe.js ├── tslinter │ ├── .dockerignore │ ├── .vscode │ │ └── launch.json │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── common │ │ │ └── logging.ts │ │ ├── config │ │ │ ├── Application.ts │ │ │ └── Express.ts │ │ ├── controllers │ │ │ └── HelloWorld.ts │ │ └── index.ts │ ├── tsconfig.json │ └── tslint.json └── typescript-express-session │ ├── .dockerignore │ ├── .vscode │ └── launch.json │ ├── Dockerfile │ ├── package-lock.json │ ├── package.json │ ├── src │ ├── common │ │ └── logging.ts │ ├── config │ │ ├── Application.ts │ │ └── Express.ts │ ├── controllers │ │ └── HelloWorld.ts │ └── index.ts │ └── tsconfig.json ├── LICENSE ├── README.md └── shopping cart microservices └── products-catalog -with-docker ├── .vscode └── launch.json ├── Dockerfile ├── config └── default.json ├── docker-compose.yml ├── package-lock.json ├── package.json ├── products-catalog -with-docker.rar ├── src ├── Index.ts ├── business-layer │ └── validator │ │ ├── ProductValidationProcessor.ts │ │ └── ProductValidationSchema.ts ├── data-layer │ ├── adapters │ │ └── MongoAccess.ts │ ├── data-abstracts │ │ └── repositories │ │ │ ├── IProductDocument.ts │ │ │ ├── ProductRepository.ts │ │ │ ├── ProductSchema.ts │ │ │ └── index.ts │ ├── data-agents │ │ └── ProductDataAgent.ts │ └── models │ │ └── ProductModel.ts ├── middleware │ ├── common │ │ └── Logging.ts │ ├── config │ │ ├── Application.ts │ │ └── Express.ts │ └── custom-middleware │ │ └── MyMiddleWare.ts └── service-layer │ ├── controllers │ └── ProductsController.ts │ ├── request │ └── IProductRequest.ts │ └── responses │ └── IProductResponse.ts └── tsconfig.json /Chapter02/first-microservice/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter02/first-microservice/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter02/first-microservice/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter02/first-microservice/dist/common/logging.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const winston = require("winston"); 4 | exports.logger = new winston.Logger(); 5 | const env = 'development'; 6 | // Development Logger 7 | if (env === 'development') { 8 | exports.logger.add(winston.transports.Console, { 9 | type: 'verbose', 10 | colorize: true, 11 | prettyPrint: true, 12 | handleExceptions: true, 13 | humanReadableUnhandledException: true 14 | }); 15 | } 16 | process.on('unhandledRejection', function (reason, p) { 17 | exports.logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 18 | }); 19 | //# sourceMappingURL=logging.js.map -------------------------------------------------------------------------------- /Chapter02/first-microservice/dist/common/logging.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/common/logging.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AAEtB,QAAA,MAAM,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;AAE3C,MAAM,GAAG,GAAG,aAAa,CAAC;AAE1B,qBAAqB;AACrB,EAAE,CAAA,CAAC,GAAG,KAAK,aAAa,CAAC,CAAC,CAAC;IACzB,cAAM,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE;QACrC,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,IAAI;QACjB,gBAAgB,EAAE,IAAI;QACtB,+BAA+B,EAAE,IAAI;KACtC,CAAC,CAAC;AACL,CAAC;AAED,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,UAAU,MAAM,EAAE,CAAC;IAClD,cAAM,CAAC,IAAI,CAAC,uEAAuE,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;AAC/G,CAAC,CAAC,CAAC"} -------------------------------------------------------------------------------- /Chapter02/first-microservice/dist/config/Application.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const logging_1 = require("../common/logging"); 4 | const Express_1 = require("./Express"); 5 | class Application { 6 | constructor() { 7 | this.express = new Express_1.ExpressConfig(); 8 | const port = 3000; 9 | this.server = this.express.app.listen(port, () => { 10 | logging_1.logger.info(`Server Started! Express: http://localhost:${port}`); 11 | }); 12 | } 13 | } 14 | exports.Application = Application; 15 | //# sourceMappingURL=Application.js.map -------------------------------------------------------------------------------- /Chapter02/first-microservice/dist/config/Application.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"Application.js","sourceRoot":"","sources":["../../src/config/Application.ts"],"names":[],"mappings":";;AAAA,+CAA2C;AAC3C,uCAA0C;AAE1C;IAKE;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAa,EAAE,CAAC;QAEnC,MAAM,IAAI,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YAC/C,gBAAM,CAAC,IAAI,CAAC,6CAA6C,IAAI,EAAE,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACH,CAAC;CAEA;AAdD,kCAcC"} -------------------------------------------------------------------------------- /Chapter02/first-microservice/dist/config/Express.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"Express.js","sourceRoot":"","sources":["../../src/config/Express.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AACnC,6BAA6B;AAC7B,0CAA0C;AAC1C,6DAAuD;AACvD,6BAA6B;AAE7B;IAEE;QACE,IAAI,CAAC,GAAG,GAAG,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QACzD,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAED,gBAAgB;QACd,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;QAChE,wHAAwH;QACpH,sCAAgB,CAAC,IAAI,CAAC,GAAG,EAAC;YACtB,WAAW,EAAC,CAAC,eAAe,GAAC,OAAO,CAAC;SACxC,CAAC,CAAC;IACN,CAAC;CAED;AAlBD,sCAkBC"} -------------------------------------------------------------------------------- /Chapter02/first-microservice/dist/controllers/HelloWorld.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"HelloWorld.js","sourceRoot":"","sources":["../../src/controllers/HelloWorld.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,6DAA4E;AAG5E,IAAa,UAAU,GAAvB;IAEA;IAEA,CAAC;IAEK,GAAG;;YACN,MAAM,CAAC,EAAC,KAAK,EAAC,uCAAuC,EAAC,CAAC;QAC1D,CAAC;KAAA;CAEA,CAAA;AAJD;IADC,yBAAG,CAAC,GAAG,CAAC;;;;qCAGR;AARY,UAAU;IADtB,gCAAU,CAAC,cAAc,CAAC;;GACd,UAAU,CAUtB;AAVY,gCAAU"} -------------------------------------------------------------------------------- /Chapter02/first-microservice/dist/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //reflect-metadata shim is required, requirement of routing-controllers module. 4 | require("reflect-metadata"); 5 | const Application_1 = require("./config/Application"); 6 | exports.default = new Application_1.Application(); 7 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /Chapter02/first-microservice/dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,+EAA+E;AAC/E,4BAA0B;AAC1B,sDAAmD;AAEnD,kBAAe,IAAI,yBAAW,EAAE,CAAC"} -------------------------------------------------------------------------------- /Chapter02/first-microservice/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter02/first-microservice/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter02/first-microservice/src/config/Express.ts: -------------------------------------------------------------------------------- 1 | import * as express from 'express'; 2 | import * as cors from 'cors'; 3 | import * as bodyParser from 'body-parser'; 4 | import { useExpressServer } from 'routing-controllers'; 5 | import * as path from 'path'; 6 | 7 | export class ExpressConfig{ 8 | app: express.Express; 9 | constructor() { 10 | this.app = express(); 11 | this.app.use(cors()); 12 | this.app.use(bodyParser.json()); 13 | this.app.use(bodyParser.urlencoded({ extended: false })); 14 | this.setUpControllers(); 15 | } 16 | 17 | setUpControllers(){ 18 | const controllersPath = path.resolve('dist', 'controllers'); 19 | //useExpressServer has lots of options, can be viewed at node_modules\routing-controllers\RoutingControllersOptions.d.ts 20 | useExpressServer(this.app,{ 21 | controllers:[controllersPath+"/*.js"] 22 | }); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Chapter02/first-microservice/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"}; 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter02/first-microservice/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter02/handing-asynchronous-nature/dist/async_await_example.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"async_await_example.js","sourceRoot":"","sources":["../src/async_await_example.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,iCAA0B;AAE1B,MAAM,UAAU,GAAG,GAAS,EAAE;IAC1B,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,IAAI,SAAS,GAAC,MAAM,eAAK,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;IAC9E,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,SAAS,GAAC,MAAM,eAAK,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;IAC9E,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC,CAAA,CAAA;AAED,UAAU,EAAE,CAAC;AAIb,oBAAoB"} -------------------------------------------------------------------------------- /Chapter02/handing-asynchronous-nature/dist/multiple_parallel.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"multiple_parallel.js","sourceRoot":"","sources":["../src/multiple_parallel.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,iCAA0B;AAE1B;;QACI,MAAM,CAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAE,GAAG,MACvB,OAAO,CAAC,GAAG,CAAC,CAAE,MAAM,eAAK,CAAC,GAAG,CAAC,8CAA8C,CAAC;YAC/D,MAAM,eAAK,CAAC,GAAG,CAAC,8CAA8C,CAAC;YAC/D,MAAM,eAAK,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAE,CAAC,CAAA;QAC5F,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;CAAA;AAED,yBAAyB,EAAE,CAAC"} -------------------------------------------------------------------------------- /Chapter02/handing-asynchronous-nature/dist/yield.js: -------------------------------------------------------------------------------- 1 | //# sourceMappingURL=yield.js.map -------------------------------------------------------------------------------- /Chapter02/handing-asynchronous-nature/dist/yield.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"yield.js","sourceRoot":"","sources":["../src/yield.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /Chapter02/handing-asynchronous-nature/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "handing-asynchronous-nature", 3 | "version": "1.0.0", 4 | "description": "handling aysnchronous nature", 5 | "scripts": {}, 6 | "author": "parth ghiya", 7 | "license": "ISC", 8 | "devDependencies": { 9 | "@types/node": "^8.5.1" 10 | }, 11 | "dependencies": { 12 | "axios": "^0.17.1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter02/handing-asynchronous-nature/src/async_await_example.ts: -------------------------------------------------------------------------------- 1 | import axios from 'Axios'; 2 | 3 | const asyncDemo1 = async () => { 4 | console.log("simple async call"); 5 | let asyncReq1=await axios.get('https://jsonplaceholder.typicode.com/posts/1'); 6 | console.log(asyncReq1.data); 7 | let asyncReq2=await axios.get('https://jsonplaceholder.typicode.com/posts/1'); 8 | console.log(asyncReq2.data); 9 | } 10 | 11 | asyncDemo1(); 12 | 13 | 14 | 15 | //map,filter,reduce. -------------------------------------------------------------------------------- /Chapter02/handing-asynchronous-nature/src/multiple_parallel.ts: -------------------------------------------------------------------------------- 1 | import axios from 'Axios'; 2 | 3 | async function executeParallelAsyncTasks () { 4 | const [ valueA, valueB, valueC ] = await 5 | Promise.all([ await axios.get('https://jsonplaceholder.typicode.com/posts/1'), 6 | await axios.get('https://jsonplaceholder.typicode.com/posts/2'), 7 | await axios.get('https://jsonplaceholder.typicode.com/posts/3') ]) 8 | console.log("first response is ",valueA.data); 9 | console.log(" second response is ",valueB.data); 10 | console.log("third response is ",valueC.data); 11 | } 12 | executeParallelAsyncTasks(); -------------------------------------------------------------------------------- /Chapter02/node-clusters/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter02/node-clusters/dist/app.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AACnC,0CAA0C;AAG1C,kDAAkD;AAClD;IAGI;;OAEG;IACH;QACI,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,CAAC;QACzB,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,uCAAuC;IAC3C,CAAC;IAEO,UAAU;QACd,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;QAC3D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACjE,CAAC;IAGO,MAAM;QACV,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAE9B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YAC/B,GAAG,CAAC,IAAI,CAAC;gBACL,OAAO,EAAE,+CAA+C;aAC3D,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC;CACJ;AA/BD,0BA+BC"} -------------------------------------------------------------------------------- /Chapter02/node-clusters/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "clusters", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "body-parser": "^1.18.2", 8 | "cookie-parser": "^1.4.3", 9 | "debug": "^3.1.0", 10 | "express": "^4.16.2", 11 | "typescript": "^2.6.2" 12 | }, 13 | "devDependencies": { 14 | "@types/debug": "0.0.30", 15 | "@types/node": "^8.0.58", 16 | "@types/body-parser": "^1.16.8", 17 | "@types/express": "^4.0.39" 18 | }, 19 | "scripts": {}, 20 | "author": "parth ghiya", 21 | "license": "ISC" 22 | } 23 | -------------------------------------------------------------------------------- /Chapter02/node-streams/dist/stream_test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"stream_test.js","sourceRoot":"","sources":["../src/stream_test.ts"],"names":[],"mappings":";;AAAA,mDAAkD;AAElD,8FAA8F;AAC9F,IAAI,MAAM,GAAG,IAAI,+BAAe,CAAC,CAAE,OAAO,EAAE,OAAO,CAAE,CAAC,CAAC;AAEvD,8DAA8D;AAC9D,MAAM,CAAC,EAAE,CAAC,UAAU,EAAE;IAClB,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AAClD,CAAC,CAAC,CAAC;AAEH,iEAAiE;AACjE,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAC,KAAK,EAAE,uBAAuB,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;AAC5F,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAC,KAAK,EAAC,0BAA0B,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;AAChG,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAC,KAAK,EAAE,0BAA0B,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;AAChG,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAC,KAAK,EAAE,wBAAwB,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;AAE9F,MAAM,CAAC,GAAG,EAAE,CAAC"} -------------------------------------------------------------------------------- /Chapter02/node-streams/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodestreams", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@types/node": { 8 | "version": "8.0.58", 9 | "resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.58.tgz", 10 | "integrity": "sha512-V746iUU7eHNdzQipoACuguDlVhC7IHK8CES1jSkuFt352wwA84BCWPXaGekBd7R5XdNK5ReHONDVKxlL9IreAw==" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter02/node-streams/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodestreams", 3 | "version": "1.0.0", 4 | "description": "this is project for custom transform stream implementation", 5 | "scripts": { 6 | "start":"tsc && node .\\dist\\stream_test.js" 7 | }, 8 | "author": "parth ghiya", 9 | "license": "ISC", 10 | "devDependencies": { 11 | "@types/node": "^8.0.58" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter02/node-streams/src/stream_test.ts: -------------------------------------------------------------------------------- 1 | import { FilterTransform } from "./filter_stream"; 2 | 3 | //we create object of our custom transformation & pass phone and email as sensitive properties 4 | let filter = new FilterTransform([ 'phone', 'email' ]); 5 | 6 | //create a readable stream that reads the transformed objects. 7 | filter.on('readable', function () { 8 | console.log("Transformation:-",filter.read()); 9 | }); 10 | 11 | //create a writable stream that writes data to get it transformed 12 | filter.write({ name: 'Parth', phone: 'xxxxx-xxxxx',email: 'ghiya.parth@gmail.com', id: 1 }); 13 | filter.write({ name: 'Dhruvil', phone: 'xxxxx-xxxxx',email:'dhruvil.thaker@gmail.com', id: 2 }); 14 | filter.write({ name: 'Dhaval', phone: 'xxxxx-xxxxx',email: 'dhaval.marthak@gmail.com', id: 3 }); 15 | filter.write({ name: 'Shruti', phone: 'xxxxx-xxxxx',email: 'shruti.patel@gmail.com', id: 4 }); 16 | 17 | filter.end(); -------------------------------------------------------------------------------- /Chapter02/node-streams/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "moduleResolution": "node", 5 | "module": "commonjs", 6 | "declaration": false, 7 | "noLib": false, 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "sourceMap": true, 11 | "pretty": true, 12 | "allowUnreachableCode": true, 13 | "allowUnusedLabels": true, 14 | "noImplicitAny": true, 15 | "noImplicitReturns": false, 16 | "noImplicitUseStrict": false, 17 | "outDir": "dist/", 18 | //"baseUrl": "src/", 19 | "listFiles": false, 20 | "noEmitHelpers": true 21 | }, 22 | "include": [ 23 | "src/**/*" 24 | ], 25 | "exclude": [ 26 | "node_modules" 27 | ], 28 | "compileOnSave": true 29 | } 30 | -------------------------------------------------------------------------------- /Chapter03/using_baconjs/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter03/using_baconjs/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter03/using_baconjs/src/controllers/HelloBacon.ts: -------------------------------------------------------------------------------- 1 | import * as Bacon from 'baconjs'; 2 | import { Controller, Get, JsonController, Req, Res, Param } from 'routing-controllers'; 3 | import { Request,Response } from 'express'; 4 | import {BaconService} from '../services/BaconService'; 5 | 6 | @Controller('/hello-bacon') 7 | export class HelloBacon { 8 | 9 | constructor(private baconService:BaconService){ 10 | 11 | } 12 | 13 | @Get('/:productId') 14 | async get(@Req() req:Request,@Res() res:Response,@Param("productId") productId:number) { 15 | let resp:any; 16 | this.baconService.baconService(productId) 17 | .flatMap((x)=>{ 18 | return x==null || undefined ?"No Product Found" : x; 19 | }) 20 | .onValue((o:string)=>{ 21 | resp=o; 22 | }) 23 | return resp; 24 | } 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Chapter03/using_baconjs/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter03/using_baconjs/src/services/BaconService.ts: -------------------------------------------------------------------------------- 1 | import {Service} from "typedi"; 2 | import * as Bacon from 'baconjs'; 3 | 4 | @Service() 5 | export class BaconService{ 6 | 7 | private productMap:any={ 8 | 1:"Mobile", 9 | 2:"Telivision", 10 | 3:"Book", 11 | 4:"Tablet" 12 | } 13 | 14 | baconService(productId:number){ 15 | return Bacon.constant(this.productMap[productId]) 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter03/using_highlandjs/file1.txt: -------------------------------------------------------------------------------- 1 | this is file1 2 | this is file1 3 | this is file1 4 | this is file1 5 | this is file1 6 | this is file1 7 | this is file1 8 | this is file1 9 | this is file1 10 | this is file1 -------------------------------------------------------------------------------- /Chapter03/using_highlandjs/file2.txt: -------------------------------------------------------------------------------- 1 | this is file2 2 | this is file2 3 | this is file2 4 | this is file2 5 | this is file2 6 | this is file2 7 | this is file2 8 | this is file2 9 | this is file2 10 | this is file2 -------------------------------------------------------------------------------- /Chapter03/using_highlandjs/file3.txt: -------------------------------------------------------------------------------- 1 | this is file3 2 | this is file3 3 | this is file3 4 | this is file3 5 | this is file3 6 | this is file3 7 | this is file3 8 | this is file3 9 | this is file3 10 | this is file3 -------------------------------------------------------------------------------- /Chapter03/using_highlandjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "using_highlandjs", 3 | "version": "1.0.0", 4 | "description": "this sample uses highland js methods in typescript nodejs project ", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "npm run clean && npm run build && node ./dist/index.js", 8 | "clean": "node ./node_modules/rimraf/bin.js dist", 9 | "build": "node ./node_modules/typescript/bin/tsc" 10 | }, 11 | "keywords": [ 12 | "typescript", 13 | "microservices", 14 | "nodejs", 15 | "reactive", 16 | "extensions" 17 | ], 18 | "author": "parth ghiya", 19 | "license": "ISC", 20 | "dependencies": { 21 | "highland": "^2.11.1", 22 | "typescript": "^2.6.2", 23 | "rimraf": "^2.6.2" 24 | }, 25 | "devDependencies": { 26 | "@types/node": "^8.0.58", 27 | "@types/highland": "^2.10.6" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter03/using_highlandjs/src/index.ts: -------------------------------------------------------------------------------- 1 | import * as highland from "highland"; 2 | import { Stream } from "stream"; 3 | import * as fs from "fs"; 4 | 5 | var readFile =highland.wrapCallback(fs.readFile); 6 | console.log("started at",new Date()); 7 | 8 | var filenames = highland(['file1.txt', 'file2.txt', 'file3.txt']); 9 | filenames 10 | .map(readFile) 11 | .parallel(10) //reads up to 10 times at a time 12 | .errors((err:any,rethrow:any)=>{ 13 | console.log(err); 14 | rethrow(); 15 | }) 16 | .each((x:Stream)=>{ 17 | console.log("---"); 18 | console.log(x.toString()); 19 | console.log("---"); 20 | }); 21 | console.log("finished at",new Date()); 22 | -------------------------------------------------------------------------------- /Chapter03/using_rxjs/src/rx_error_handling.ts: -------------------------------------------------------------------------------- 1 | import * as Rx from "Rxjs/Rx"; 2 | /* 3 | retry: Retries an observable sequence a specific number of times should an error occur. 4 | */ 5 | const source1 = Rx.Observable.interval(1000); 6 | const example1 = source1.flatMap(val => { 7 | if (val > 5) {return Rx.Observable.throw('Error!');} 8 | return Rx.Observable.of(val); 9 | }) 10 | .retry(2); 11 | const subscribe1 = example1.subscribe({ 12 | next: val => console.log(val), 13 | error: val => console.log(`${val}: Retried 2 times then quit!`) 14 | }); 15 | 16 | -------------------------------------------------------------------------------- /Chapter03/using_rxjs/src/rx_filtering.ts: -------------------------------------------------------------------------------- 1 | import * as Rx from "Rxjs/Rx"; 2 | 3 | /** 4 | Debounce:Ignore emitted values that take less than specified time. 5 | Example if we set debounce on 1 second, than any values which are emitted before 1 second 6 | will be ignored 7 | */ 8 | const example = Rx.Observable.of('before 1 sec', 'before 1 sec', 'before 1 sec','before 1 sec', 'After 1 sec'); 9 | const debouncedExample = example.debounce(() => Rx.Observable.timer(1000)); 10 | const subscribe = debouncedExample.subscribe(val => console.log(val)); 11 | 12 | /** 13 | Throttle: Emit value only when duration, determined by provided function, has passed. 14 | */ 15 | const source = Rx.Observable.interval(1000); 16 | const example2 = source.throttle(val => Rx.Observable.interval(2000)); 17 | const subscribe2 = example2.subscribe(val => console.log(val)); -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}\\dist\\Index.js", 13 | "outFiles": [ 14 | "${workspaceFolder}/dist/Index.js" 15 | ] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | #install dependencies 8 | COPY package.json /usr/src/app 9 | RUN npm install 10 | #bundle app src 11 | COPY . /usr/src/app 12 | EXPOSE 3000 13 | CMD [ "npm" , "start" ] 14 | -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "express":{ 3 | "port":8081, 4 | "debug":5858, 5 | "host":"products-service" 6 | }, 7 | "mongo":{ 8 | "urlClient": "mongodb://127.0.0.1:27017/products" 9 | }, 10 | "loglevel": "info" 11 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | app: 4 | container_name: app 5 | build: ./ 6 | restart: always 7 | ports: 8 | - "3000:8081" 9 | links: 10 | - mongo 11 | mongo: 12 | container_name: mongo 13 | image: mongo 14 | volumes: 15 | - ./data:/data/db 16 | ports: 17 | - "27017:27017" 18 | -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/src/Index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './middleware/config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/src/business-layer/validator/ProductValidationProcessor.ts: -------------------------------------------------------------------------------- 1 | import { validate } from "class-validator"; 2 | import { ProductValidationSchema } from './ProductValidationSchema'; 3 | import { forEach, pick} from 'lodash'; 4 | 5 | async function validateProductRequest(productReqObj:any): Promise{ 6 | let validProductData = new ProductValidationSchema(productReqObj); 7 | let validationResults = await validate(validProductData); 8 | let constraints =[] 9 | if(validationResults && validationResults.length > 0 ){ 10 | forEach(validationResults, (item)=>{ 11 | constraints.push(pick(item, 'constraints', 'property')); 12 | }); 13 | } 14 | return constraints; 15 | } 16 | 17 | 18 | 19 | export {validateProductRequest} -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/src/data-layer/data-abstracts/repositories/IProductDocument.ts: -------------------------------------------------------------------------------- 1 | import mongoose=require('mongoose'); 2 | 3 | export interface IProductDocument extends mongoose.Document{ 4 | id:string, 5 | ownerId:String, 6 | brand:{ 7 | id:number, 8 | name:string 9 | }, 10 | lastUpdated:Date, 11 | createdAt:Date, 12 | name:string, 13 | feedbackEmail:string, 14 | description:string, 15 | category:string, 16 | desc:[{ 17 | lang:string, 18 | val:string 19 | }], 20 | shipping:{ 21 | dimensions:{ 22 | height:number, 23 | width:number, 24 | length:number 25 | }, 26 | weight:number 27 | }, 28 | attrs:[{ 29 | name:string, 30 | value:string 31 | }] 32 | 33 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/src/data-layer/data-abstracts/repositories/ProductRepository.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Model,model } from "mongoose"; 3 | import { MongooseAccess } from "../../../data-layer/adapters/MongoAccess"; 4 | import { IProductDocument } from "../../../data-layer/data-abstracts/repositories/IProductDocument"; 5 | import { ProductSchema } from "../../../data-layer/data-abstracts/repositories/ProductSchema"; 6 | 7 | export type ProductMod = Model; 8 | 9 | export const ProductRepo:ProductMod = MongooseAccess.mongooseConnection.model("product", ProductSchema); 10 | 11 | -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/src/data-layer/data-abstracts/repositories/index.ts: -------------------------------------------------------------------------------- 1 | export {IProductDocument} from './IProductDocument'; 2 | export {ProductRepo} from './ProductRepository'; 3 | export {ProductSchema} from './ProductSchema'; -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/src/middleware/common/Logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/src/middleware/custom-middleware/MyMiddleWare.ts: -------------------------------------------------------------------------------- 1 | import {ExpressMiddlewareInterface} from "routing-controllers"; 2 | 3 | export class MyMiddleware implements ExpressMiddlewareInterface { // interface implementation is optional 4 | 5 | constructor(){} 6 | use(request: any, response: any, next?: (err?: any) => any): any { 7 | console.log("custom middleware gets called."); 8 | next(); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/src/service-layer/request/IProductRequest.ts: -------------------------------------------------------------------------------- 1 | export interface IProductCreateRequest{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog -with-docker/src/service-layer/responses/IProductResponse.ts: -------------------------------------------------------------------------------- 1 | export interface IProductResponse{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}\\dist\\Index.js", 13 | "outFiles": [ 14 | "${workspaceFolder}/dist/Index.js" 15 | ] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | #install dependencies 8 | COPY package.json /usr/src/app 9 | RUN npm install 10 | #bundle app src 11 | COPY . /usr/src/app 12 | EXPOSE 3000 13 | CMD [ "npm" , "start" ] 14 | -------------------------------------------------------------------------------- /Chapter04/products-catalog/config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "express":{ 3 | "port":8081, 4 | "debug":5858, 5 | "host":"products-service" 6 | }, 7 | "mongo":{ 8 | "urlClient": "mongodb://127.0.0.1:27017/products" 9 | }, 10 | "loglevel": "info" 11 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | app: 4 | container_name: app 5 | build: ./ 6 | restart: always 7 | ports: 8 | - "3000:8081" 9 | links: 10 | - mongo 11 | mongo: 12 | container_name: mongo 13 | image: mongo 14 | volumes: 15 | - ./data:/data/db 16 | ports: 17 | - "27017:27017" 18 | -------------------------------------------------------------------------------- /Chapter04/products-catalog/src/Index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './middleware/config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter04/products-catalog/src/business-layer/validator/ProductValidationProcessor.ts: -------------------------------------------------------------------------------- 1 | import { validate } from "class-validator"; 2 | import { ProductValidationSchema } from './ProductValidationSchema'; 3 | import { forEach, pick} from 'lodash'; 4 | 5 | async function validateProductRequest(productReqObj:any): Promise{ 6 | let validProductData = new ProductValidationSchema(productReqObj); 7 | let validationResults = await validate(validProductData); 8 | let constraints =[] 9 | if(validationResults && validationResults.length > 0 ){ 10 | forEach(validationResults, (item)=>{ 11 | constraints.push(pick(item, 'constraints', 'property')); 12 | }); 13 | } 14 | return constraints; 15 | } 16 | 17 | 18 | 19 | export {validateProductRequest} -------------------------------------------------------------------------------- /Chapter04/products-catalog/src/data-layer/data-abstracts/repositories/IProductDocument.ts: -------------------------------------------------------------------------------- 1 | import mongoose=require('mongoose'); 2 | 3 | export interface IProductDocument extends mongoose.Document{ 4 | id:string, 5 | ownerId:String, 6 | brand:{ 7 | id:number, 8 | name:string 9 | }, 10 | lastUpdated:Date, 11 | createdAt:Date, 12 | name:string, 13 | feedbackEmail:string, 14 | description:string, 15 | category:string, 16 | desc:[{ 17 | lang:string, 18 | val:string 19 | }], 20 | shipping:{ 21 | dimensions:{ 22 | height:number, 23 | width:number, 24 | length:number 25 | }, 26 | weight:number 27 | }, 28 | attrs:[{ 29 | name:string, 30 | value:string 31 | }] 32 | 33 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog/src/data-layer/data-abstracts/repositories/ProductRepository.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Model,model } from "mongoose"; 3 | import { MongooseAccess } from "../../../data-layer/adapters/MongoAccess"; 4 | import { IProductDocument } from "../../../data-layer/data-abstracts/repositories/IProductDocument"; 5 | import { ProductSchema } from "../../../data-layer/data-abstracts/repositories/ProductSchema"; 6 | 7 | export type ProductMod = Model; 8 | 9 | export const ProductRepo:ProductMod = MongooseAccess.mongooseConnection.model("product", ProductSchema); 10 | 11 | -------------------------------------------------------------------------------- /Chapter04/products-catalog/src/data-layer/data-abstracts/repositories/index.ts: -------------------------------------------------------------------------------- 1 | export {IProductDocument} from './IProductDocument'; 2 | export {ProductRepo} from './ProductRepository'; 3 | export {ProductSchema} from './ProductSchema'; -------------------------------------------------------------------------------- /Chapter04/products-catalog/src/middleware/common/Logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter04/products-catalog/src/middleware/custom-middleware/MyMiddleWare.ts: -------------------------------------------------------------------------------- 1 | import {ExpressMiddlewareInterface} from "routing-controllers"; 2 | 3 | export class MyMiddleware implements ExpressMiddlewareInterface { // interface implementation is optional 4 | 5 | constructor(){} 6 | use(request: any, response: any, next?: (err?: any) => any): any { 7 | console.log("custom middleware gets called."); 8 | next(); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog/src/service-layer/request/IProductRequest.ts: -------------------------------------------------------------------------------- 1 | export interface IProductCreateRequest{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter04/products-catalog/src/service-layer/responses/IProductResponse.ts: -------------------------------------------------------------------------------- 1 | export interface IProductResponse{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter05/api_gateway/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "api_gateway", 3 | "version": "1.0.0", 4 | "description": "this is gateway for shopping cart microservices based on example in book typescript microservices", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "api", 11 | "gateway", 12 | "docker", 13 | "typescript", 14 | "microservices", 15 | "parth", 16 | "ghiya" 17 | ], 18 | "author": "parth ghiya", 19 | "license": "ISC" 20 | } 21 | -------------------------------------------------------------------------------- /Chapter06/consul/consul-producer/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}/dist/index.js", 13 | "outFiles": [ 14 | "${workspaceFolder}/**/*.js" 15 | ] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /Chapter06/consul/consul-producer/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter06/consul/consul-producer/src/config/Express.ts: -------------------------------------------------------------------------------- 1 | import * as express from 'express'; 2 | import * as cors from 'cors'; 3 | import * as bodyParser from 'body-parser'; 4 | import { useExpressServer } from 'routing-controllers'; 5 | import * as path from 'path'; 6 | 7 | export class ExpressConfig{ 8 | app: express.Express; 9 | constructor() { 10 | this.app = express(); 11 | this.app.use(cors()); 12 | this.app.use(bodyParser.json()); 13 | this.app.use(bodyParser.urlencoded({ extended: false })); 14 | this.setUpControllers(); 15 | } 16 | 17 | setUpControllers(){ 18 | const controllersPath = path.resolve('dist', 'controllers'); 19 | //useExpressServer has lots of options, can be viewed at node_modules\routing-controllers\RoutingControllersOptions.d.ts 20 | useExpressServer(this.app,{ 21 | controllers:[controllersPath+"/*.js"] 22 | }); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Chapter06/consul/consul-producer/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"} 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter06/consul/consul-producer/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter06/eureka/eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter06/eureka/eureka-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/TypeScript-Microservices/91aa8e66696971354245c826bc5d23f885e8c27a/Chapter06/eureka/eureka-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter06/eureka/eureka-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter06/eureka/eureka-server/src/main/java/com/microservices/demo/discovery/demoservicediscovery/DemoServiceDiscoveryApplication.java: -------------------------------------------------------------------------------- 1 | package com.microservices.demo.discovery.demoservicediscovery; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | 8 | @EnableEurekaServer 9 | @SpringBootApplication 10 | public class DemoServiceDiscoveryApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(DemoServiceDiscoveryApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter06/eureka/eureka-server/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=EmployeeEurekaServer 2 | eureka.client.serviceUrl.defaultZone:http://localhost:9091/eureka/ 3 | server.port=9091 4 | eureka.client.register-with-eureka=false 5 | eureka.client.fetch-registry=false 6 | eureka.server.enableSelfPreservation=false 7 | -------------------------------------------------------------------------------- /Chapter06/eureka/eureka-server/src/test/java/com/microservices/demo/discovery/demoservicediscovery/DemoServiceDiscoveryApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.microservices.demo.discovery.demoservicediscovery; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DemoServiceDiscoveryApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/eureka/eureka-service-discovery/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/index.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter06/eureka/eureka-service-discovery/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter06/eureka/eureka-service-discovery/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | import { Eureka } from 'eureka-js-client'; 4 | import { EurekaService } from '../config/EurekaService'; 5 | 6 | export class Application { 7 | 8 | server: any; 9 | express: ExpressConfig; 10 | 11 | constructor() { 12 | this.express = new ExpressConfig(); 13 | const port = 4000; 14 | this.server = this.express.app.listen(port, () => {logger.info(`Server Started! Express: http://localhost:${port}`);}); 15 | //start eureka client 16 | EurekaService.getClient().start(); 17 | process.on('SIGINT', ()=> { //stop client 18 | EurekaService.getClient().stop(); 19 | this.server.close() 20 | }); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /Chapter06/eureka/eureka-service-discovery/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter06/eureka/first-microservice-register/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter06/eureka/first-microservice-register/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/index.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter06/eureka/first-microservice-register/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter06/eureka/first-microservice-register/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter06/eureka/first-microservice-register/src/config/Express.ts: -------------------------------------------------------------------------------- 1 | import * as express from 'express'; 2 | import * as cors from 'cors'; 3 | import * as bodyParser from 'body-parser'; 4 | import { useExpressServer } from 'routing-controllers'; 5 | import * as path from 'path'; 6 | 7 | export class ExpressConfig{ 8 | app: express.Express; 9 | constructor() { 10 | this.app = express(); 11 | this.app.use(cors()); 12 | this.app.use(bodyParser.json()); 13 | this.app.use(bodyParser.urlencoded({ extended: false })); 14 | this.setUpControllers(); 15 | } 16 | 17 | setUpControllers(){ 18 | const controllersPath = path.resolve('dist', 'controllers'); 19 | //useExpressServer has lots of options, can be viewed at node_modules\routing-controllers\RoutingControllersOptions.d.ts 20 | useExpressServer(this.app,{ 21 | controllers:[controllersPath+"/*.js"] 22 | }); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Chapter06/eureka/first-microservice-register/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController } from 'routing-controllers'; 2 | 3 | @Controller('') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"} 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter06/eureka/first-microservice-register/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/consumer/.bitmap: -------------------------------------------------------------------------------- 1 | /* THIS IS A BIT-AUTO-GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */ 2 | 3 | { 4 | "version": "0.12.13" 5 | } -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/consumer/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "consumer", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@bit/parthghiya.tsms.common.cache-reader": { 8 | "version": "1.0.0", 9 | "resolved": "https://node.bitsrc.io/parthghiya.tsms.common.cache-reader/-/parthghiya.tsms.common.cache-reader-1.0.0.tgz", 10 | "integrity": "sha1-laxwd7D5wdi08oOnqdEm/3MLhwk=" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/consumer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "consumer", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@bit/parthghiya.tsms.common.cache-reader": "^1.0.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/bit.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "compiler": "bit.envs/compilers/typescript@0.0.3", 4 | "tester": "bit.envs/testers/mocha@0.0.12" 5 | }, 6 | "dependencies": {}, 7 | "componentsDefaultDirectory": "components/{namespace}/{name}", 8 | "packageManager": "npm" 9 | } -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/hello world: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/TypeScript-Microservices/91aa8e66696971354245c826bc5d23f885e8c27a/Chapter07/bit-code-sharing/demo-microservice/hello world -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/src/common/cacheReader.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/TypeScript-Microservices/91aa8e66696971354245c826bc5d23f885e8c27a/Chapter07/bit-code-sharing/demo-microservice/src/common/cacheReader.ts -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/src/config/Express.ts: -------------------------------------------------------------------------------- 1 | import * as express from 'express'; 2 | import * as cors from 'cors'; 3 | import * as bodyParser from 'body-parser'; 4 | import { useExpressServer } from 'routing-controllers'; 5 | import * as path from 'path'; 6 | 7 | export class ExpressConfig{ 8 | app: express.Express; 9 | constructor() { 10 | this.app = express(); 11 | this.app.use(cors()); 12 | this.app.use(bodyParser.json()); 13 | this.app.use(bodyParser.urlencoded({ extended: false })); 14 | this.setUpControllers(); 15 | } 16 | 17 | setUpControllers(){ 18 | const controllersPath = path.resolve('dist', 'controllers'); 19 | //useExpressServer has lots of options, can be viewed at node_modules\routing-controllers\RoutingControllersOptions.d.ts 20 | useExpressServer(this.app,{ 21 | controllers:[controllersPath+"/*.js"] 22 | }); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"}; 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/src/tests/cacheReader.spec.ts: -------------------------------------------------------------------------------- 1 | import {expect} from 'chai'; 2 | 3 | describe("hello world mocha test service", function(){ 4 | it("should create the user with the correct name",()=>{ 5 | let helloDef=()=>'hello world'; 6 | let helloRes=helloDef(); 7 | expect(helloRes).to.equal('hello world'); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /Chapter07/bit-code-sharing/demo-microservice/src/tests/logging.spec.ts: -------------------------------------------------------------------------------- 1 | import {expect} from 'chai'; 2 | 3 | describe("hello world mocha test service", function(){ 4 | it("should create the user with the correct name",()=>{ 5 | let helloDef=()=>'hello world'; 6 | let helloRes=helloDef(); 7 | expect(helloRes).to.equal('hello world'); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /Chapter07/http2/README.md: -------------------------------------------------------------------------------- 1 | openssl genrsa -des3 -passout pass:x -out server.pass.key 2048 2 | ... 3 | 4 | openssl rsa -passin pass:x -in server.pass.key -out server.key 5 | writing RSA key 6 | 7 | rm server.pass.key 8 | 9 | openssl req -new -key server.key -out server.csr 10 | ... 11 | Country Name (2 letter code) [AU]:US 12 | State or Province Name (full name) [Some-State]:California 13 | ... 14 | A challenge password []: 15 | ... 16 | 17 | openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt -------------------------------------------------------------------------------- /Chapter07/http2/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter07/http2/src/config/Express.ts: -------------------------------------------------------------------------------- 1 | import * as express from 'express'; 2 | import * as cors from 'cors'; 3 | import * as bodyParser from 'body-parser'; 4 | import { useExpressServer } from 'routing-controllers'; 5 | import * as path from 'path'; 6 | 7 | export class ExpressConfig{ 8 | app: express.Express; 9 | constructor() { 10 | this.app = express(); 11 | this.app.use(cors()); 12 | this.app.use(bodyParser.json()); 13 | this.app.use(bodyParser.urlencoded({ extended: false })); 14 | this.setUpControllers(); 15 | } 16 | 17 | setUpControllers(){ 18 | const controllersPath = path.resolve('dist', 'controllers'); 19 | //useExpressServer has lots of options, can be viewed at node_modules\routing-controllers\RoutingControllersOptions.d.ts 20 | useExpressServer(this.app,{ 21 | controllers:[controllersPath+"/*.js"] 22 | }); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Chapter07/http2/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"}; 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter07/http2/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter07/hystrix/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter07/hystrix/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter07/hystrix/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter07/hystrix/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter07/hystrix/src/config/HystrixStream.ts: -------------------------------------------------------------------------------- 1 | 2 | export function hystrixStream (circuitBreaker:any) { 3 | return (request:any, response:any) => { 4 | response.writeHead(200, { 5 | 'Content-Type': 'text/event-stream', 6 | 'Cache-Control': 'no-cache', 7 | 'Connection': 'keep-alive'}); 8 | response.write('retry: 10000\n'); 9 | response.write('event: connecttime\n'); 10 | 11 | circuitBreaker.stats.pipe(response); 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /Chapter07/hystrix/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"}; 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter07/hystrix/src/custom_types/opossum.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'opossum'; 2 | declare module 'circuitBreaker'; -------------------------------------------------------------------------------- /Chapter07/hystrix/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter07/kafka/node-producer/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter07/kafka/node-producer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-producer", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "body-parser": "^1.18.2", 8 | "cookie-parser": "^1.4.3", 9 | "debug": "^3.1.0", 10 | "express": "^4.16.2", 11 | "typescript": "^2.6.2" 12 | }, 13 | "devDependencies": { 14 | "@types/debug": "0.0.30", 15 | "@types/node": "^8.0.58", 16 | "@types/body-parser": "^1.16.8", 17 | "@types/express": "^4.0.39" 18 | }, 19 | "scripts": { 20 | "start":"tsc && node ./dist/app.ts" 21 | }, 22 | "author": "parth ghiya", 23 | "license": "ISC" 24 | } 25 | -------------------------------------------------------------------------------- /Chapter07/netflix cloud/eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter07/netflix cloud/eureka-server/src/main/java/com/microservices/demo/discovery/demoservicediscovery/DemoServiceDiscoveryApplication.java: -------------------------------------------------------------------------------- 1 | package com.microservices.demo.discovery.demoservicediscovery; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | 8 | @EnableEurekaServer 9 | @SpringBootApplication 10 | public class DemoServiceDiscoveryApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(DemoServiceDiscoveryApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter07/netflix cloud/first-microservice-register-node/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter07/netflix cloud/first-microservice-register-node/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/index.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter07/netflix cloud/first-microservice-register-node/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter07/netflix cloud/first-microservice-register-node/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter07/netflix cloud/first-microservice-register-node/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController } from 'routing-controllers'; 2 | 3 | @Controller('') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"} 12 | } 13 | 14 | @Get('/hello-nodejs') 15 | async getNode(): Promise { 16 | return {"msg":"This is first Typescript Microservice from Node.js prpogram"} 17 | } 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Chapter07/netflix cloud/first-microservice-register-node/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter07/netflix cloud/java-microservice/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter07/netflix cloud/java-microservice/src/main/java/com/polyglot/java/javamicroservice/JavaMicroserviceApplication.java: -------------------------------------------------------------------------------- 1 | package com.polyglot.java.javamicroservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class JavaMicroserviceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(JavaMicroserviceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter07/netflix cloud/java-microservice/src/main/java/com/polyglot/java/javamicroservice/service/DemoController.java: -------------------------------------------------------------------------------- 1 | package com.polyglot.java.javamicroservice.service; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import com.polyglot.java.javamicroservice.model.ProductModel; 7 | 8 | @RestController 9 | public class DemoController { 10 | 11 | @GetMapping(value = "/product") 12 | public ProductModel firstPage() { 13 | 14 | ProductModel prm = new ProductModel(); 15 | prm.setName("parth"); 16 | prm.setDescription("demo product 1"); 17 | prm.setProductId("#12345463e56"); 18 | return prm; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter07/netflix cloud/zuuul-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter07/netflix cloud/zuuul-server/src/main/java/com/microservices/demo/discovery/netflixosss/NetflixOsssApplication.java: -------------------------------------------------------------------------------- 1 | package com.microservices.demo.discovery.netflixosss; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableZuulProxy 11 | 12 | public class NetflixOsssApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(NetflixOsssApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter07/standalone-hystrix-dashboard-all.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/TypeScript-Microservices/91aa8e66696971354245c826bc5d23f885e8c27a/Chapter07/standalone-hystrix-dashboard-all.jar -------------------------------------------------------------------------------- /Chapter07/thrift-rpc/src/config/default.ts: -------------------------------------------------------------------------------- 1 | export const gateway = { 2 | //server is where the gateway runs, it consumes response from productservice. 3 | server: { 4 | hostName: 'localhost', 5 | port: 9000, 6 | path: '/', 7 | }, 8 | //from where we are going to get product data. 9 | client: { 10 | hostName: 'localhost', 11 | port: 8095, 12 | path: '/', 13 | }, 14 | } 15 | 16 | export const product = { 17 | server: { 18 | hostName: 'localhost', 19 | port: 8095, 20 | path: '/', 21 | }, 22 | client: { 23 | hostName: 'localhost', 24 | port: 8085, 25 | path: '/', 26 | }, 27 | } 28 | 29 | export const identity = { 30 | server: { 31 | hostName: 'localhost', 32 | port: 8085, 33 | path: '/', 34 | }, 35 | } 36 | -------------------------------------------------------------------------------- /Chapter07/thrift-rpc/src/index.ts: -------------------------------------------------------------------------------- 1 | import './gateway/server'; 2 | import './popularity/server'; 3 | import './product/server'; 4 | -------------------------------------------------------------------------------- /Chapter07/thrift-rpc/thrift/popularity/PopularityService.thrift: -------------------------------------------------------------------------------- 1 | namespace js com.popularity 2 | struct Popularity { 3 | 1: required i32 id 4 | 2: required i32 totalStars 5 | 3: required string review 6 | 4: required i32 productId 7 | } 8 | exception PopularityServiceException { 9 | 1: required string message 10 | } 11 | service PopularityService { 12 | Popularity getPopularityByProduct(4: i32 productId) throws (1: PopularityServiceException exp) 13 | } -------------------------------------------------------------------------------- /Chapter07/thrift-rpc/thrift/product/ProductService.thrift: -------------------------------------------------------------------------------- 1 | namespace js com.product 2 | 3 | include 'popularity/PopularityService.thrift' 4 | 5 | struct Product { 6 | 1: required i32 id 7 | 2: required PopularityService.Popularity feedback 8 | 3: required string productInfo 9 | 4: required string productType 10 | } 11 | 12 | exception ProductServiceException { 13 | 1: required string message 14 | } 15 | 16 | service ProductService { 17 | Product getProduct(1: i32 productId) throws (1: ProductServiceException exp) 18 | } -------------------------------------------------------------------------------- /Chapter07/thrift-rpc/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "sourceMap": true, 7 | "declaration": true, 8 | "rootDir": "./src", 9 | "outDir": "./dist", 10 | "noEmitOnError": true, 11 | "strict": true, 12 | "noUnusedLocals": true, 13 | "pretty": true 14 | }, 15 | "exclude": [ 16 | "node_modules", 17 | "dist" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}\\dist\\Index.js", 13 | "outFiles": [ 14 | "${workspaceFolder}/dist/Index.js" 15 | ] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | #install dependencies 8 | COPY package.json /usr/src/app 9 | RUN npm install 10 | #bundle app src 11 | COPY . /usr/src/app 12 | EXPOSE 3000 13 | CMD [ "npm" , "start" ] 14 | -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "express":{ 3 | "port":8081, 4 | "debug":5858, 5 | "host":"products-service" 6 | }, 7 | "mongo":{ 8 | "urlClient": "mongodb://127.0.0.1:27017/products" 9 | }, 10 | "loglevel": "info" 11 | } -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | app: 4 | container_name: app 5 | build: ./ 6 | restart: always 7 | ports: 8 | - "3000:8081" 9 | links: 10 | - mongo 11 | mongo: 12 | container_name: mongo 13 | image: mongo 14 | volumes: 15 | - ./data:/data/db 16 | ports: 17 | - "27017:27017" 18 | -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/src/Index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './middleware/config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/src/business-layer/validator/ProductValidationProcessor.ts: -------------------------------------------------------------------------------- 1 | import { validate } from "class-validator"; 2 | import { ProductValidationSchema } from './ProductValidationSchema'; 3 | import { forEach, pick} from 'lodash'; 4 | 5 | async function validateProductRequest(productReqObj:any): Promise{ 6 | let validProductData = new ProductValidationSchema(productReqObj); 7 | let validationResults = await validate(validProductData); 8 | let constraints =[] 9 | if(validationResults && validationResults.length > 0 ){ 10 | forEach(validationResults, (item)=>{ 11 | constraints.push(pick(item, 'constraints', 'property')); 12 | }); 13 | } 14 | return constraints; 15 | } 16 | 17 | 18 | 19 | export {validateProductRequest} -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/src/data-layer/data-abstracts/repositories/IProductDocument.ts: -------------------------------------------------------------------------------- 1 | import mongoose=require('mongoose'); 2 | 3 | export interface IProductDocument extends mongoose.Document{ 4 | id:string, 5 | ownerId:String, 6 | brand:{ 7 | id:number, 8 | name:string 9 | }, 10 | lastUpdated:Date, 11 | createdAt:Date, 12 | name:string, 13 | feedbackEmail:string, 14 | description:string, 15 | category:string, 16 | desc:[{ 17 | lang:string, 18 | val:string 19 | }], 20 | shipping:{ 21 | dimensions:{ 22 | height:number, 23 | width:number, 24 | length:number 25 | }, 26 | weight:number 27 | }, 28 | attrs:[{ 29 | name:string, 30 | value:string 31 | }] 32 | 33 | } -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/src/data-layer/data-abstracts/repositories/ProductRepository.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Model,model } from "mongoose"; 3 | import { MongooseAccess } from "../../../data-layer/adapters/MongoAccess"; 4 | import { IProductDocument } from "../../../data-layer/data-abstracts/repositories/IProductDocument"; 5 | import { ProductSchema } from "../../../data-layer/data-abstracts/repositories/ProductSchema"; 6 | 7 | export type ProductMod = Model; 8 | 9 | export const ProductRepo:ProductMod = MongooseAccess.mongooseConnection.model("product", ProductSchema); 10 | 11 | -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/src/data-layer/data-abstracts/repositories/index.ts: -------------------------------------------------------------------------------- 1 | export {IProductDocument} from './IProductDocument'; 2 | export {ProductRepo} from './ProductRepository'; 3 | export {ProductSchema} from './ProductSchema'; -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/src/middleware/common/Logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/src/middleware/custom-middleware/MyMiddleWare.ts: -------------------------------------------------------------------------------- 1 | import {ExpressMiddlewareInterface} from "routing-controllers"; 2 | 3 | export class MyMiddleware implements ExpressMiddlewareInterface { // interface implementation is optional 4 | 5 | constructor(){} 6 | use(request: any, response: any, next?: (err?: any) => any): any { 7 | console.log("custom middleware gets called."); 8 | next(); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/src/service-layer/controllers/SwaggerController.ts: -------------------------------------------------------------------------------- 1 | import { JsonController, Req, Res, Get } from "routing-controllers"; 2 | import { SwaggerSpec } from "../../middleware/config/Express"; 3 | 4 | 5 | 6 | @JsonController('/swagger') 7 | export class SwaggerController { 8 | constructor(){} 9 | 10 | @Get('/swagger.json') 11 | async swaggerDoc(@Req() req, @Res() res){ 12 | return SwaggerSpec.getSwaggerJSON(); 13 | } 14 | } -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/src/service-layer/request/IProductRequest.ts: -------------------------------------------------------------------------------- 1 | export interface IProductCreateRequest{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter08/bottom-up-swagger/src/service-layer/responses/IProductResponse.ts: -------------------------------------------------------------------------------- 1 | export interface IProductResponse{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter08/cpu-profiling-demo/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter08/cpu-profiling-demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cpu-profiling-demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "body-parser": "^1.18.2", 8 | "cookie-parser": "^1.4.3", 9 | "debug": "^3.1.0", 10 | "express": "^4.16.2", 11 | "typescript": "^2.6.2" 12 | }, 13 | "devDependencies": { 14 | "@types/debug": "0.0.30", 15 | "@types/node": "^8.0.58", 16 | "@types/body-parser": "^1.16.8", 17 | "@types/express": "^4.0.39" 18 | }, 19 | "scripts": {}, 20 | "author": "parth ghiya", 21 | "license": "ISC" 22 | } 23 | -------------------------------------------------------------------------------- /Chapter08/heapdump_demo/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter08/heapdump_demo/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter08/heapdump_demo/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | import * as heapdump from 'heapdump'; 4 | import * as path from 'path'; 5 | 6 | export class Application { 7 | 8 | server: any; 9 | express: ExpressConfig; 10 | 11 | constructor() { 12 | this.express = new ExpressConfig(); 13 | 14 | const port = 3000; 15 | this.server = this.express.app.listen(port, () => { 16 | logger.info(`Server Started! Express: http://localhost:${port}`); 17 | }); 18 | heapdump.writeSnapshot(path.join(__dirname,`${Date.now()}.heapsnapshot`),(err,filename)=>{ 19 | if(err){ 20 | console.log("failed to create heap snapshot at time of start"); 21 | }else{ 22 | console.log("dump written to",filename); 23 | } 24 | 25 | }); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Chapter08/heapdump_demo/src/config/Express.ts: -------------------------------------------------------------------------------- 1 | import * as express from 'express'; 2 | import * as cors from 'cors'; 3 | import * as bodyParser from 'body-parser'; 4 | import { useExpressServer } from 'routing-controllers'; 5 | import * as path from 'path'; 6 | 7 | export class ExpressConfig{ 8 | app: express.Express; 9 | constructor() { 10 | this.app = express(); 11 | this.app.use(cors()); 12 | this.app.use(bodyParser.json()); 13 | this.app.use(bodyParser.urlencoded({ extended: false })); 14 | this.setUpControllers(); 15 | } 16 | 17 | setUpControllers(){ 18 | const controllersPath = path.resolve('dist', 'controllers'); 19 | //useExpressServer has lots of options, can be viewed at node_modules\routing-controllers\RoutingControllersOptions.d.ts 20 | useExpressServer(this.app,{ 21 | controllers:[controllersPath+"/*.js"] 22 | }); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Chapter08/heapdump_demo/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"}; 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter08/heapdump_demo/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter08/hello_world_swagger.yaml: -------------------------------------------------------------------------------- 1 | swagger: "2.0" 2 | info: 3 | version: "1.0" 4 | title: "Hello World API" 5 | paths: 6 | /hello/{product}: 7 | get: 8 | description: Returns a description for the product! 9 | parameters: 10 | - name: product 11 | in: path 12 | type: string 13 | required: true 14 | description: The name of the product to greet. 15 | responses: 16 | 200: 17 | description: Returns the greeting. 18 | schema: 19 | type: string 20 | 400: 21 | description: Invalid characters in "product" were provided. -------------------------------------------------------------------------------- /Chapter08/products-catalog/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}\\dist\\Index.js", 13 | "outFiles": [ 14 | "${workspaceFolder}/dist/Index.js" 15 | ] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /Chapter08/products-catalog/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | #install dependencies 8 | COPY package.json /usr/src/app 9 | RUN npm install 10 | #bundle app src 11 | COPY . /usr/src/app 12 | EXPOSE 3000 13 | CMD [ "npm" , "start" ] 14 | -------------------------------------------------------------------------------- /Chapter08/products-catalog/config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "express":{ 3 | "port":8081, 4 | "debug":5858, 5 | "host":"products-service" 6 | }, 7 | "mongo":{ 8 | "urlClient": "mongodb://127.0.0.1:27017/products" 9 | }, 10 | "loglevel": "info" 11 | } -------------------------------------------------------------------------------- /Chapter08/products-catalog/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | app: 4 | container_name: app 5 | build: ./ 6 | restart: always 7 | ports: 8 | - "3000:8081" 9 | links: 10 | - mongo 11 | mongo: 12 | container_name: mongo 13 | image: mongo 14 | volumes: 15 | - ./data:/data/db 16 | ports: 17 | - "27017:27017" 18 | -------------------------------------------------------------------------------- /Chapter08/products-catalog/src/Index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './middleware/config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter08/products-catalog/src/business-layer/validator/ProductValidationProcessor.ts: -------------------------------------------------------------------------------- 1 | import { validate } from "class-validator"; 2 | import { ProductValidationSchema } from './ProductValidationSchema'; 3 | import { forEach, pick} from 'lodash'; 4 | 5 | async function validateProductRequest(productReqObj:any): Promise{ 6 | let validProductData = new ProductValidationSchema(productReqObj); 7 | let validationResults = await validate(validProductData); 8 | let constraints =[] 9 | if(validationResults && validationResults.length > 0 ){ 10 | forEach(validationResults, (item)=>{ 11 | constraints.push(pick(item, 'constraints', 'property')); 12 | }); 13 | } 14 | return constraints; 15 | } 16 | 17 | 18 | 19 | export {validateProductRequest} -------------------------------------------------------------------------------- /Chapter08/products-catalog/src/data-layer/data-abstracts/repositories/IProductDocument.ts: -------------------------------------------------------------------------------- 1 | import mongoose=require('mongoose'); 2 | 3 | export interface IProductDocument extends mongoose.Document{ 4 | id:string, 5 | ownerId:String, 6 | brand:{ 7 | id:number, 8 | name:string 9 | }, 10 | lastUpdated:Date, 11 | createdAt:Date, 12 | name:string, 13 | feedbackEmail:string, 14 | description:string, 15 | category:string, 16 | desc:[{ 17 | lang:string, 18 | val:string 19 | }], 20 | shipping:{ 21 | dimensions:{ 22 | height:number, 23 | width:number, 24 | length:number 25 | }, 26 | weight:number 27 | }, 28 | attrs:[{ 29 | name:string, 30 | value:string 31 | }] 32 | 33 | } -------------------------------------------------------------------------------- /Chapter08/products-catalog/src/data-layer/data-abstracts/repositories/ProductRepository.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Model,model } from "mongoose"; 3 | import { MongooseAccess } from "../../../data-layer/adapters/MongoAccess"; 4 | import { IProductDocument } from "../../../data-layer/data-abstracts/repositories/IProductDocument"; 5 | import { ProductSchema } from "../../../data-layer/data-abstracts/repositories/ProductSchema"; 6 | 7 | export type ProductMod = Model; 8 | 9 | export const ProductRepo:ProductMod = MongooseAccess.mongooseConnection.model("product", ProductSchema); 10 | 11 | -------------------------------------------------------------------------------- /Chapter08/products-catalog/src/data-layer/data-abstracts/repositories/index.ts: -------------------------------------------------------------------------------- 1 | export {IProductDocument} from './IProductDocument'; 2 | export {ProductRepo} from './ProductRepository'; 3 | export {ProductSchema} from './ProductSchema'; -------------------------------------------------------------------------------- /Chapter08/products-catalog/src/middleware/common/Logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter08/products-catalog/src/middleware/custom-middleware/MyMiddleWare.ts: -------------------------------------------------------------------------------- 1 | import {ExpressMiddlewareInterface} from "routing-controllers"; 2 | 3 | export class MyMiddleware implements ExpressMiddlewareInterface { // interface implementation is optional 4 | 5 | constructor(){} 6 | use(request: any, response: any, next?: (err?: any) => any): any { 7 | console.log("custom middleware gets called."); 8 | next(); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Chapter08/products-catalog/src/service-layer/request/IProductRequest.ts: -------------------------------------------------------------------------------- 1 | export interface IProductCreateRequest{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter08/products-catalog/src/service-layer/responses/IProductResponse.ts: -------------------------------------------------------------------------------- 1 | export interface IProductResponse{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/.dockerignore: -------------------------------------------------------------------------------- 1 | .git/ 2 | *.iml 3 | out/ 4 | *.ipr 5 | *.iws 6 | classpath.txt 7 | version.properties 8 | .project 9 | .classpath 10 | lib/* 11 | build/* 12 | generated-files/* 13 | generated-sources/* 14 | generated-code/* 15 | *.swp 16 | *.swo 17 | *.bak 18 | project/ 19 | samples/* 20 | target/ 21 | .idea/ 22 | .lib/ 23 | .DS_Store 24 | 25 | # Not needed in a linux container 26 | bin/windows/* 27 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/.java-version: -------------------------------------------------------------------------------- 1 | oracle64-1.8.0.152 2 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 SmartBear Software 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) 6 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen-cli/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8-jre-alpine 2 | 3 | ADD target/swagger-codegen-cli.jar /opt/swagger-codegen-cli/swagger-codegen-cli.jar 4 | 5 | ENTRYPOINT ["java", "-jar", "/opt/swagger-codegen-cli/swagger-codegen-cli.jar"] 6 | 7 | CMD ["help"] -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Langs.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.cmd; 2 | 3 | import ch.lambdaj.collection.LambdaIterable; 4 | import io.airlift.airline.Command; 5 | import io.swagger.codegen.CodegenConfig; 6 | 7 | import static ch.lambdaj.Lambda.on; 8 | import static ch.lambdaj.collection.LambdaCollections.with; 9 | import static java.util.ServiceLoader.load; 10 | 11 | /** 12 | * User: lanwen Date: 24.03.15 Time: 20:25 13 | */ 14 | @Command(name = "langs", description = "Shows available langs") 15 | public class Langs implements Runnable { 16 | @Override 17 | public void run() { 18 | LambdaIterable langs = 19 | with(load(CodegenConfig.class)).extract(on(CodegenConfig.class).getName()); 20 | System.out.printf("Available languages: %s%n", langs); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/ValidateException.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.cmd; 2 | 3 | /** 4 | * Created by takuro on 2017/05/02. 5 | */ 6 | public class ValidateException extends RuntimeException { 7 | } 8 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/.gitignore: -------------------------------------------------------------------------------- 1 | /.settings/ 2 | /test-output/ 3 | /bin/ 4 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModelType.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen; 2 | 3 | public enum CodegenModelType { 4 | 5 | MODEL(CodegenModel.class), 6 | OPERATION(CodegenOperation.class), 7 | PARAMETER(CodegenParameter.class), 8 | PROPERTY(CodegenProperty.class), 9 | RESPONSE(CodegenResponse.class), 10 | SECURITY(CodegenSecurity.class); 11 | 12 | private final Class defaultImplementation; 13 | 14 | private CodegenModelType(Class defaultImplementation) { 15 | this.defaultImplementation = defaultImplementation; 16 | } 17 | 18 | public Class getDefaultImplementation() { 19 | return defaultImplementation; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/Generator.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen; 2 | 3 | import java.io.File; 4 | import java.util.List; 5 | 6 | public interface Generator { 7 | Generator opts(ClientOptInput opts); 8 | 9 | List generate(); 10 | } -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/GlobalSupportingFile.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen; 2 | 3 | public class GlobalSupportingFile extends SupportingFile { 4 | 5 | GlobalSupportingFile(String templateFile, String folder, String destinationFilename) { 6 | super(templateFile, folder, destinationFilename); 7 | } 8 | 9 | GlobalSupportingFile(String templateFile, String destinationFilename) { 10 | super(templateFile, destinationFilename); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/auth/AuthMethod.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.auth; 2 | 3 | public interface AuthMethod { 4 | String getType(); 5 | 6 | void setType(String type); 7 | } -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/ignore/rules/EverythingRule.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.ignore.rules; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * An ignore rule which matches everything. 7 | */ 8 | public class EverythingRule extends Rule { 9 | EverythingRule(List syntax, String definition) { 10 | super(syntax, definition); 11 | } 12 | 13 | @Override 14 | public Boolean matches(String relativePath) { 15 | return true; 16 | } 17 | 18 | @Override 19 | protected Operation getExcludeOperation(){ return Operation.EXCLUDE_AND_TERMINATE; } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/ignore/rules/FileRule.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.ignore.rules; 2 | 3 | import java.nio.file.FileSystems; 4 | import java.nio.file.PathMatcher; 5 | import java.util.List; 6 | 7 | public class FileRule extends Rule { 8 | 9 | private PathMatcher matcher = null; 10 | 11 | FileRule(List syntax, String definition) { 12 | super(syntax, definition); 13 | matcher = FileSystems.getDefault().getPathMatcher("glob:"+this.getPattern()); 14 | } 15 | 16 | @Override 17 | public Boolean matches(String relativePath) { 18 | return matcher.matches(FileSystems.getDefault().getPath(relativePath)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/ignore/rules/InvalidRule.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.ignore.rules; 2 | 3 | import java.util.List; 4 | 5 | public class InvalidRule extends Rule { 6 | private final String reason; 7 | 8 | InvalidRule(List syntax, String definition, String reason) { 9 | super(syntax, definition); 10 | this.reason = reason; 11 | } 12 | 13 | @Override 14 | public Boolean matches(String relativePath) { 15 | return null; 16 | } 17 | 18 | @Override 19 | public Operation evaluate(String relativePath) { 20 | return Operation.NOOP; 21 | } 22 | 23 | public String getReason() { 24 | return reason; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/ignore/rules/ParserException.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.ignore.rules; 2 | 3 | public class ParserException extends Exception { 4 | /** 5 | * Constructs a new exception with the specified detail message. The 6 | * cause is not initialized, and may subsequently be initialized by 7 | * a call to {@link #initCause}. 8 | * 9 | * @param message the detail message. The detail message is saved for 10 | * later retrieval by the {@link #getMessage()} method. 11 | */ 12 | public ParserException(String message) { 13 | super(message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/ignore/rules/Part.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.ignore.rules; 2 | 3 | class Part { 4 | private final IgnoreLineParser.Token token; 5 | private final String value; 6 | 7 | public Part(IgnoreLineParser.Token token, String value) { 8 | this.token = token; 9 | this.value = value; 10 | } 11 | 12 | public Part(IgnoreLineParser.Token token) { 13 | this.token = token; 14 | this.value = token.getPattern(); 15 | } 16 | 17 | public IgnoreLineParser.Token getToken() { 18 | return token; 19 | } 20 | 21 | public String getValue() { 22 | return value; 23 | } 24 | } -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/BeanValidationExtendedFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface BeanValidationExtendedFeatures { 4 | 5 | // Language (implementing Client/Server) supports automatic BeanValidation (1.1) 6 | public static final String USE_BEANVALIDATION_FEATURE = "useBeanValidationFeature"; 7 | 8 | public void setUseBeanValidationFeature(boolean useBeanValidationFeature); 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/BeanValidationFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface BeanValidationFeatures { 4 | 5 | // Language supports generating BeanValidation-Annotations 6 | public static final String USE_BEANVALIDATION = "useBeanValidation"; 7 | 8 | public void setUseBeanValidation(boolean useBeanValidation); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/CXFFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | /** 4 | * Features supported by CXF 3 (client + server) 5 | * 6 | */ 7 | public interface CXFFeatures extends LoggingFeatures, GzipFeatures, BeanValidationFeatures { 8 | 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/GzipFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface GzipFeatures { 4 | 5 | public static final String USE_GZIP_FEATURE = "useGzipFeature"; 6 | 7 | public void setUseGzipFeature(boolean useGzipFeature); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/GzipTestFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface GzipTestFeatures { 4 | 5 | public static final String USE_GZIP_FEATURE_FOR_TESTS = "useGzipFeatureForTests"; 6 | 7 | public void setUseGzipFeatureForTests(boolean useGzipFeatureForTests); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/JbossFeature.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface JbossFeature { 4 | 5 | public static final String GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR = "generateJbossDeploymentDescriptor"; 6 | 7 | public void setGenerateJbossDeploymentDescriptor(boolean generateJbossDeploymentDescriptor); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/LoggingFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface LoggingFeatures extends BeanValidationFeatures { 4 | 5 | public static final String USE_LOGGING_FEATURE = "useLoggingFeature"; 6 | 7 | public void setUseLoggingFeature(boolean useLoggingFeature); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/LoggingTestFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface LoggingTestFeatures { 4 | public static final String USE_LOGGING_FEATURE_FOR_TESTS = "useLoggingFeatureForTests"; 5 | 6 | public void setUseLoggingFeatureForTests(boolean useLoggingFeatureForTests); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/OptionalFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface OptionalFeatures { 4 | 5 | // Language supports generating Optional Types 6 | String USE_OPTIONAL = "useOptional"; 7 | 8 | void setUseOptional(boolean useOptional); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/PerformBeanValidationFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface PerformBeanValidationFeatures { 4 | 5 | // Language supports performing BeanValidation 6 | public static final String PERFORM_BEANVALIDATION = "performBeanValidation"; 7 | 8 | public void setPerformBeanValidation(boolean performBeanValidation); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/SpringFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface SpringFeatures extends BeanValidationFeatures { 4 | 5 | public static final String GENERATE_SPRING_APPLICATION = "generateSpringApplication"; 6 | 7 | public static final String GENERATE_SPRING_BOOT_APPLICATION = "generateSpringBootApplication"; 8 | 9 | public static final String USE_SPRING_ANNOTATION_CONFIG = "useSpringAnnotationConfig"; 10 | 11 | public void setGenerateSpringApplication(boolean useGenerateSpringApplication); 12 | 13 | public void setGenerateSpringBootApplication(boolean generateSpringBootApplication); 14 | 15 | public void setUseSpringAnnotationConfig(boolean useSpringAnnotationConfig); 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/SwaggerFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface SwaggerFeatures { 4 | 5 | public static final String USE_SWAGGER_FEATURE = "useSwaggerFeature"; 6 | 7 | public void setUseSwaggerFeature(boolean useSwaggerFeature); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/SwaggerUIFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface SwaggerUIFeatures extends CXFFeatures { 4 | 5 | public static final String USE_SWAGGER_UI = "useSwaggerUI"; 6 | 7 | public void setUseSwaggerUI(boolean useSwaggerUI); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/features/UseGenericResponseFeatures.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.languages.features; 2 | 3 | public interface UseGenericResponseFeatures { 4 | 5 | // Language supports generating generic Jaxrs or native return types 6 | public static final String USE_GENERIC_RESPONSE = "useGenericResponse"; 7 | 8 | public void setUseGenericResponse(boolean useGenericResponse); 9 | } 10 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/mustache/UppercaseLambda.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.mustache; 2 | 3 | import com.samskivert.mustache.Mustache; 4 | import com.samskivert.mustache.Template; 5 | 6 | import java.io.IOException; 7 | import java.io.Writer; 8 | 9 | /** 10 | * Converts text in a fragment to uppercase. 11 | * 12 | * Register: 13 | *
14 |  * additionalProperties.put("uppercase", new UppercaseLambda());
15 |  * 
16 | * 17 | * Use: 18 | *
19 |  * {{#uppercase}}{{summary}}{{/uppercase}}
20 |  * 
21 | */ 22 | public class UppercaseLambda implements Mustache.Lambda { 23 | @Override 24 | public void execute(Template.Fragment fragment, Writer writer) throws IOException { 25 | String text = fragment.execute(); 26 | writer.write(text.toUpperCase()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-codegen/src/main/java/io/swagger/codegen/utils/ImplementationVersion.java: -------------------------------------------------------------------------------- 1 | package io.swagger.codegen.utils; 2 | 3 | public class ImplementationVersion { 4 | public static String read() { 5 | // Assumes this version is required at runtime. This could be modified to use a properties file like the CLI. 6 | String compiledVersion = ImplementationVersion.class.getPackage().getImplementationVersion(); 7 | if(compiledVersion != null) { 8 | return compiledVersion; 9 | } 10 | 11 | return "unset"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-generator/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | 3 | WORKDIR /generator 4 | 5 | COPY target/lib/jetty-runner* /generator/jetty-runner.jar 6 | COPY target/*.war /generator/swagger-generator.war 7 | 8 | ENV GENERATOR_HOST=https://generator.swaggerhub.com/api/swagger.json 9 | 10 | EXPOSE 8080 11 | 12 | CMD ["java", "-jar", "/generator/jetty-runner.jar", "/generator/swagger-generator.war"] 13 | 14 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-generator/src/main/java/io/swagger/generator/util/JacksonJsonProvider.java: -------------------------------------------------------------------------------- 1 | package io.swagger.generator.util; 2 | 3 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; 6 | import io.swagger.util.Json; 7 | 8 | import javax.ws.rs.Produces; 9 | import javax.ws.rs.core.MediaType; 10 | import javax.ws.rs.ext.Provider; 11 | 12 | @Provider 13 | @Produces({MediaType.APPLICATION_JSON}) 14 | public class JacksonJsonProvider extends JacksonJaxbJsonProvider { 15 | private static ObjectMapper commonMapper = Json.mapper(); 16 | 17 | public JacksonJsonProvider() { 18 | super.setMapper(commonMapper); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-generator/src/main/java/io/swagger/generator/util/ValidationException.java: -------------------------------------------------------------------------------- 1 | package io.swagger.generator.util; 2 | 3 | public class ValidationException extends Exception { 4 | private static final long serialVersionUID = 6861195361018260380L; 5 | private int code; 6 | private String msg; 7 | 8 | public ValidationException(String msg) { 9 | super(msg); 10 | } 11 | 12 | public int getCode() { 13 | return code; 14 | } 15 | 16 | public void setCode(int code) { 17 | this.code = code; 18 | } 19 | 20 | @Override 21 | public String getMessage() { 22 | return msg; 23 | } 24 | 25 | public void setMessage(String msg) { 26 | this.msg = msg; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/modules/swagger-generator/src/main/java/io/swagger/generator/util/ValidationMessage.java: -------------------------------------------------------------------------------- 1 | package io.swagger.generator.util; 2 | 3 | public class ValidationMessage { 4 | private String path, message, severity; 5 | 6 | public String getPath() { 7 | return path; 8 | } 9 | 10 | public void setPath(String path) { 11 | this.path = path; 12 | } 13 | 14 | public String getMessage() { 15 | return message; 16 | } 17 | 18 | public void setMessage(String message) { 19 | this.message = message; 20 | } 21 | 22 | public String getSeverity() { 23 | return severity; 24 | } 25 | 26 | public void setSeverity(String severity) { 27 | this.severity = severity; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/swagger-codegen-master/run-in-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -exo pipefail 3 | 4 | cd "$(dirname ${BASH_SOURCE})" 5 | 6 | maven_cache_repo="${HOME}/.m2/repository" 7 | 8 | mkdir -p "${maven_cache_repo}" 9 | 10 | docker run --rm -it \ 11 | -w /gen \ 12 | -e GEN_DIR=/gen \ 13 | -e MAVEN_CONFIG=/var/maven/.m2 \ 14 | -u "$(id -u):$(id -g)" \ 15 | -v "${PWD}:/gen" \ 16 | -v "${maven_cache_repo}:/var/maven/.m2/repository" \ 17 | --entrypoint /gen/docker-entrypoint.sh \ 18 | maven:3-jdk-7 "$@" 19 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/typescript-nodejs/.gitignore: -------------------------------------------------------------------------------- 1 | wwwroot/*.js 2 | node_modules 3 | typings 4 | -------------------------------------------------------------------------------- /Chapter08/swagger-code-gen/typescript-nodejs/.swagger-codegen/VERSION: -------------------------------------------------------------------------------- 1 | 2.4.0-SNAPSHOT -------------------------------------------------------------------------------- /Chapter08/top-down-swagger/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "top-down-swagger", 3 | "version": "1.0.0", 4 | "description": "top down approach to use swagger", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "top-down", 11 | "swagger", 12 | "Node-js", 13 | "typescript", 14 | "microservice" 15 | ], 16 | "author": "parth-ghiya", 17 | "license": "ISC", 18 | "dependencies": { 19 | "tsoa": "^2.1.4" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Chapter08/ts-http-proxy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts-http-proxy", 3 | "version": "1.0.0", 4 | "description": "this is http proxy ", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "npm run clean && npm run build && node ./dist/index.js", 8 | "clean": "node ./node_modules/rimraf/bin.js dist", 9 | "build": "node ./node_modules/typescript/bin/tsc" 10 | }, 11 | "keywords": [ 12 | "tsms", 13 | "typescript", 14 | "nodejs" 15 | ], 16 | "author": "parth ghiya", 17 | "license": "ISC", 18 | "dependencies": { 19 | "@types/http-proxy": "^1.16.1", 20 | "http-proxy": "^1.17.0", 21 | "rimraf": "^2.6.2", 22 | "typescript": "^2.8.3" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter08/ts-http-proxy/src/index.ts: -------------------------------------------------------------------------------- 1 | import * as httpProxy from 'http-proxy'; 2 | import * as http from 'http'; 3 | import { IncomingMessage, ServerResponse } from 'http'; 4 | 5 | 6 | export class ProxyServer{ 7 | private proxy:any; 8 | constructor(){ 9 | this.registerProxyServer(); 10 | this.proxy=httpProxy.createProxyServer({}); 11 | //we are passing zero server options, but we can pass lots of options such as buffer, target, agent, forward, ssl, etc. 12 | } 13 | 14 | registerProxyServer():void{ 15 | http.createServer((req:IncomingMessage,res:ServerResponse)=>{ 16 | console.log("===req.rawHeaders====",req.rawHeaders); 17 | this.proxy.web(req,res,{target:'http://127.0.0.1:3000/hello-world'}) 18 | }).listen(4000)} 19 | } 20 | 21 | 22 | new ProxyServer(); -------------------------------------------------------------------------------- /Chapter08/typescript-node-client/.gitignore: -------------------------------------------------------------------------------- 1 | wwwroot/*.js 2 | node_modules 3 | typings 4 | -------------------------------------------------------------------------------- /Chapter08/typescript-node-client/.swagger-codegen/VERSION: -------------------------------------------------------------------------------- 1 | 2.3.1 -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | #install dependencies 8 | COPY package.json /usr/src/app 9 | RUN npm install 10 | #bundle app src 11 | COPY . /usr/src/app 12 | EXPOSE 8081 13 | CMD [ "npm" , "start" ] 14 | -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "express":{ 3 | "port":8081, 4 | "debug":5858, 5 | "host":"products-service" 6 | }, 7 | "mongo":{ 8 | "urlClient": "mongodb://chapter9-mongo/products" 9 | }, 10 | "loglevel": "info" 11 | } -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | chapter9-app: 4 | container_name: chapter9-app 5 | build: ./ 6 | restart: always 7 | links: 8 | - chapter9-mongo 9 | chapter9-mongo: 10 | container_name: chapter9-mongo 11 | image: mongo 12 | volumes: 13 | - ./data:/data/db 14 | ports: 15 | - "27017:27017" 16 | nginx: 17 | restart: always 18 | build: ./nginx/ 19 | ports: 20 | - "80:80" 21 | - "443:443" 22 | volumes: 23 | - /etc/nginx/ssl:/etc/nginx/ssl 24 | volumes_from: 25 | - chapter9-app 26 | links: 27 | - chapter9-app:chapter9-app -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tutum/nginx 2 | RUN rm /etc/nginx/sites-enabled/default 3 | COPY nginx.conf /etc/nginx.conf 4 | RUN mkdir /etc/nginx/ssl 5 | COPY certs/server.key /etc/nginx/ssl/server.key 6 | COPY certs/server.crt /etc/nginx/ssl/server.crt 7 | ADD sites-enabled/ /etc/nginx/sites-enabled -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | http{ 2 | proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m; 3 | proxy_temp_path /var/tmp; 4 | include mime.types; 5 | default_type application/octet-stream; 6 | sendfile on; 7 | keepalive_timeout 65; 8 | 9 | gzip on; 10 | gzip_comp_level 6; 11 | gzip_vary on; 12 | gzip_min_length 1000; 13 | gzip_proxied any; 14 | gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 15 | gzip_buffers 16 8k; 16 | } -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/nginx/sites-enabled/nodejs_project: -------------------------------------------------------------------------------- 1 | server { 2 | 3 | listen 80; 4 | server_name product-catalog.org; 5 | access_log /var/log/nginx/nodejs_project.log; 6 | charset utf-8; 7 | 8 | location / { 9 | proxy_pass http://chapter9-app:8081; 10 | proxy_set_header Host $host; 11 | proxy_set_header X-Real-IP $remote_addr; 12 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/src/Index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './middleware/config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/src/business-layer/validator/ProductValidationProcessor.ts: -------------------------------------------------------------------------------- 1 | import { validate } from "class-validator"; 2 | import { ProductValidationSchema } from './ProductValidationSchema'; 3 | import { forEach, pick} from 'lodash'; 4 | 5 | async function validateProductRequest(productReqObj:any): Promise{ 6 | let validProductData = new ProductValidationSchema(productReqObj); 7 | let validationResults = await validate(validProductData); 8 | let constraints =[] 9 | if(validationResults && validationResults.length > 0 ){ 10 | forEach(validationResults, (item)=>{ 11 | constraints.push(pick(item, 'constraints', 'property')); 12 | }); 13 | } 14 | return constraints; 15 | } 16 | 17 | 18 | 19 | export {validateProductRequest} -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/src/data-layer/data-abstracts/repositories/IProductDocument.ts: -------------------------------------------------------------------------------- 1 | import mongoose=require('mongoose'); 2 | 3 | export interface IProductDocument extends mongoose.Document{ 4 | id:string, 5 | ownerId:String, 6 | brand:{ 7 | id:number, 8 | name:string 9 | }, 10 | lastUpdated:Date, 11 | createdAt:Date, 12 | name:string, 13 | feedbackEmail:string, 14 | description:string, 15 | category:string, 16 | desc:[{ 17 | lang:string, 18 | val:string 19 | }], 20 | shipping:{ 21 | dimensions:{ 22 | height:number, 23 | width:number, 24 | length:number 25 | }, 26 | weight:number 27 | }, 28 | attrs:[{ 29 | name:string, 30 | value:string 31 | }] 32 | 33 | } -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/src/data-layer/data-abstracts/repositories/ProductRepository.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Model,model } from "mongoose"; 3 | import { MongooseAccess } from "../../../data-layer/adapters/MongoAccess"; 4 | import { IProductDocument } from "../../../data-layer/data-abstracts/repositories/IProductDocument"; 5 | import { ProductSchema } from "../../../data-layer/data-abstracts/repositories/ProductSchema"; 6 | 7 | export type ProductMod = Model; 8 | 9 | export const ProductRepo:ProductMod = MongooseAccess.mongooseConnection.model("product", ProductSchema); 10 | 11 | -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/src/data-layer/data-abstracts/repositories/index.ts: -------------------------------------------------------------------------------- 1 | export {IProductDocument} from './IProductDocument'; 2 | export {ProductRepo} from './ProductRepository'; 3 | export {ProductSchema} from './ProductSchema'; -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/src/middleware/common/Logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/src/middleware/custom-middleware/MyMiddleWare.ts: -------------------------------------------------------------------------------- 1 | import {ExpressMiddlewareInterface} from "routing-controllers"; 2 | 3 | export class MyMiddleware implements ExpressMiddlewareInterface { // interface implementation is optional 4 | 5 | constructor(){} 6 | use(request: any, response: any, next?: (err?: any) => any): any { 7 | console.log("custom middleware gets called."); 8 | next(); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/src/service-layer/request/IProductRequest.ts: -------------------------------------------------------------------------------- 1 | export interface IProductCreateRequest{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter09/Nginx-node-mongo/src/service-layer/responses/IProductResponse.ts: -------------------------------------------------------------------------------- 1 | export interface IProductResponse{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter09/counter-metric/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter09/counter-metric/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter09/counter-metric/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter09/counter-metric/src/config/CounterMiddleware.ts: -------------------------------------------------------------------------------- 1 | import { ExpressMiddlewareInterface } from "routing-controllers"; 2 | const pmx=require('pmx').init({http:true,errors:true, custom_probes:true,network:true,ports:true}); 3 | const pmxProbe=pmx.probe(); 4 | const pmxCounter=pmxProbe.counter({ 5 | name:'request counter for Hello World Controller', 6 | agg_type:'sum' 7 | }) 8 | 9 | export class CounterMiddleWare implements ExpressMiddlewareInterface { 10 | use(request: any, response: any, next: (err?: any) => any ):any { 11 | console.log("custom middle ware"); 12 | pmxCounter.inc(); 13 | next(); 14 | } 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter09/counter-metric/src/config/Express.ts: -------------------------------------------------------------------------------- 1 | import * as express from 'express'; 2 | import * as cors from 'cors'; 3 | import * as bodyParser from 'body-parser'; 4 | import { useExpressServer } from 'routing-controllers'; 5 | import * as path from 'path'; 6 | 7 | 8 | export class ExpressConfig{ 9 | app: express.Express; 10 | pmx:any; 11 | constructor() { 12 | this.app = express(); 13 | this.app.use(cors()); 14 | this.app.use(bodyParser.json()); 15 | this.app.use(bodyParser.urlencoded({ extended: false })); 16 | this.setUpControllers(); 17 | } 18 | 19 | setUpControllers(){ 20 | const controllersPath = path.resolve('dist', 'controllers'); 21 | //useExpressServer has lots of options, can be viewed at node_modules\routing-controllers\RoutingControllersOptions.d.ts 22 | useExpressServer(this.app,{ 23 | controllers:[controllersPath+"/*.js"] 24 | }); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /Chapter09/counter-metric/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post, UseBefore } from 'routing-controllers'; 2 | import { CounterMiddleWare } from '../config/CounterMiddleware'; 3 | 4 | @UseBefore(CounterMiddleWare) 5 | @Controller('/hello-world') 6 | export class HelloWorld { 7 | private pmxVar:any; 8 | private probe:any; 9 | private metric:any; 10 | 11 | constructor(){ 12 | } 13 | 14 | @Get('/') 15 | async get(): Promise { 16 | return {"msg":"This is first Typescript Microservice"}; 17 | } 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Chapter09/counter-metric/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter09/counter-metric/src/types.ts: -------------------------------------------------------------------------------- 1 | declare module 'pmx'; -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | #install dependencies 8 | COPY package.json /usr/src/app 9 | RUN npm install 10 | #bundle app src 11 | COPY . /usr/src/app 12 | EXPOSE 3000 13 | CMD [ "npm" , "start" ] 14 | -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "express":{ 3 | "port":8081, 4 | "debug":5858, 5 | "host":"products-service" 6 | }, 7 | "mongo":{ 8 | "urlClient": "mongodb://127.0.0.1:27017/products" 9 | }, 10 | "loglevel": "info", 11 | "server_type":"production" 12 | 13 | } -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | app: 4 | container_name: app 5 | build: ./ 6 | restart: always 7 | ports: 8 | - "3000:8081" 9 | links: 10 | - mongo 11 | mongo: 12 | container_name: mongo 13 | image: mongo 14 | volumes: 15 | - ./data:/data/db 16 | ports: 17 | - "27017:27017" 18 | -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/src/Index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './middleware/config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/src/business-layer/validator/ProductValidationProcessor.ts: -------------------------------------------------------------------------------- 1 | import { validate } from "class-validator"; 2 | import { ProductValidationSchema } from './ProductValidationSchema'; 3 | import { forEach, pick} from 'lodash'; 4 | 5 | async function validateProductRequest(productReqObj:any): Promise{ 6 | let validProductData = new ProductValidationSchema(productReqObj); 7 | let validationResults = await validate(validProductData); 8 | let constraints =[] 9 | if(validationResults && validationResults.length > 0 ){ 10 | forEach(validationResults, (item)=>{ 11 | constraints.push(pick(item, 'constraints', 'property')); 12 | }); 13 | } 14 | return constraints; 15 | } 16 | 17 | 18 | 19 | export {validateProductRequest} -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/src/custom_types/winston-logzio.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'winston-logzio' -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/src/data-layer/data-abstracts/repositories/IProductDocument.ts: -------------------------------------------------------------------------------- 1 | import mongoose=require('mongoose'); 2 | 3 | export interface IProductDocument extends mongoose.Document{ 4 | id:string, 5 | ownerId:String, 6 | brand:{ 7 | id:number, 8 | name:string 9 | }, 10 | lastUpdated:Date, 11 | createdAt:Date, 12 | name:string, 13 | feedbackEmail:string, 14 | description:string, 15 | category:string, 16 | desc:[{ 17 | lang:string, 18 | val:string 19 | }], 20 | shipping:{ 21 | dimensions:{ 22 | height:number, 23 | width:number, 24 | length:number 25 | }, 26 | weight:number 27 | }, 28 | attrs:[{ 29 | name:string, 30 | value:string 31 | }] 32 | 33 | } -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/src/data-layer/data-abstracts/repositories/ProductRepository.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Model,model } from "mongoose"; 3 | import { MongooseAccess } from "../../../data-layer/adapters/MongoAccess"; 4 | import { IProductDocument } from "../../../data-layer/data-abstracts/repositories/IProductDocument"; 5 | import { ProductSchema } from "../../../data-layer/data-abstracts/repositories/ProductSchema"; 6 | 7 | export type ProductMod = Model; 8 | 9 | export const ProductRepo:ProductMod = MongooseAccess.mongooseConnection.model("product", ProductSchema); 10 | 11 | -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/src/data-layer/data-abstracts/repositories/index.ts: -------------------------------------------------------------------------------- 1 | export {IProductDocument} from './IProductDocument'; 2 | export {ProductRepo} from './ProductRepository'; 3 | export {ProductSchema} from './ProductSchema'; -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/src/middleware/custom-middleware/MyMiddleWare.ts: -------------------------------------------------------------------------------- 1 | import {ExpressMiddlewareInterface} from "routing-controllers"; 2 | 3 | export class MyMiddleware implements ExpressMiddlewareInterface { // interface implementation is optional 4 | 5 | constructor(){} 6 | use(request: any, response: any, next?: (err?: any) => any): any { 7 | console.log("custom middleware gets called."); 8 | next(); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/src/service-layer/request/IProductRequest.ts: -------------------------------------------------------------------------------- 1 | export interface IProductCreateRequest{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter09/elk-logz.io/src/service-layer/responses/IProductResponse.ts: -------------------------------------------------------------------------------- 1 | export interface IProductResponse{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter09/logstash-simple.conf: -------------------------------------------------------------------------------- 1 | input { stdin { } } 2 | output { 3 | elasticsearch { hosts => ["localhost:9200"] } 4 | stdout { codec => rubydebug } 5 | } -------------------------------------------------------------------------------- /Chapter09/meter metric/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter09/meter metric/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter09/meter metric/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter09/meter metric/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | var pmx=require('pmx'); 3 | 4 | @Controller('/hello-world') 5 | export class HelloWorld { 6 | private pmxVar:any; 7 | private probe:any; 8 | private metric:any; 9 | 10 | constructor(){ 11 | this.pmxVar=pmx.init({ 12 | http:true, 13 | errors:true, 14 | custom_probes:true, 15 | network:true, 16 | ports:true 17 | }); 18 | this.probe=this.pmxVar.probe(); 19 | this.metric=this.probe.meter({ 20 | name: 'average per minute', 21 | samples:60, 22 | timeframe:3600 23 | }) 24 | 25 | } 26 | 27 | @Get('/') 28 | async get(): Promise { 29 | this.metric.mark(); 30 | return {"msg":"This is first Typescript Microservice"}; 31 | } 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Chapter09/meter metric/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter09/meter metric/src/types.ts: -------------------------------------------------------------------------------- 1 | declare module 'pmx'; -------------------------------------------------------------------------------- /Chapter09/pmx-utilities/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter09/pmx-utilities/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter09/pmx-utilities/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter09/pmx-utilities/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | var pmx=require('pmx'); 3 | 4 | @Controller('/hello-world') 5 | export class HelloWorld { 6 | private pmxVar:any; 7 | private random:any=[]; 8 | 9 | constructor(){} 10 | 11 | 12 | @Get('/') 13 | async get(): Promise { 14 | return {"msg":"This is first Typescript Microservice"}; 15 | } 16 | 17 | 18 | @Get('/error-route') 19 | async throwError(): Promise { 20 | pmx.notify(new Error("Unexpected Exception")); 21 | return {"msg":"This is first Typescript Microservice"}; 22 | } 23 | 24 | @Get('/memory-leak') 25 | async memoryleak(): Promise { 26 | this.random.push("randommmm"); 27 | return {"msg":"This is first Typescript Microservice"}; 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Chapter09/pmx-utilities/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter09/pmx-utilities/src/types.ts: -------------------------------------------------------------------------------- 1 | declare module 'pmx'; -------------------------------------------------------------------------------- /Chapter09/prometheus-grafana/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter09/prometheus-grafana/prometheus-data/alert.rules: -------------------------------------------------------------------------------- 1 | # APIHighMedianResponseTime 2 | ALERT APIHighMedianResponseTime 3 | IF histogram_quantile(0.5, sum(rate(http_request_duration_ms_bucket[1m])) by (le, service, route, method)) > 100 4 | FOR 60s 5 | ANNOTATIONS { 6 | summary = "High median response time on {{ $labels.service }} and {{ $labels.method }} {{ $labels.route }}", 7 | description = "{{ $labels.service }}, {{ $labels.method }} {{ $labels.route }} has a median response time above 100ms (current value: {{ $value }}ms)", 8 | } -------------------------------------------------------------------------------- /Chapter09/prometheus-grafana/prometheus-data/prometheus.yml: -------------------------------------------------------------------------------- 1 | scrape_configs: 2 | - job_name: 'prometheus-demo' 3 | scrape_interval: 5s 4 | 5 | static_configs: 6 | - targets: ['10.0.2.15:4200'] 7 | labels: 8 | service: 'demo-microservice' 9 | group: 'production' 10 | rule_files: 11 | - 'alert.rules' -------------------------------------------------------------------------------- /Chapter09/prometheus-grafana/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter09/prometheus-grafana/src/config/AfterMiddleware.ts: -------------------------------------------------------------------------------- 1 | import { ExpressMiddlewareInterface, Middleware } from "routing-controllers"; 2 | import { httpRequestDurationMicroseconds } from "./metrics-modules/MetricModule"; 3 | 4 | @Middleware({ type: "after" }) 5 | export class AfterMiddleware implements ExpressMiddlewareInterface { 6 | use(request: any, response: any, next: (err?: any) => any) { 7 | console.log("called after each request"); 8 | const responseTimes=Date.now()-response.locals.startEpoch; 9 | httpRequestDurationMicroseconds 10 | .labels(request.method,request.route.path,response.statusCode) 11 | .observe(responseTimes); 12 | next(); 13 | } 14 | } -------------------------------------------------------------------------------- /Chapter09/prometheus-grafana/src/controllers/DemoRoute1.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | 3 | @Controller('/demo-one') 4 | export class DemoOne { 5 | 6 | constructor(){} 7 | 8 | @Get('/') 9 | async get(): Promise { 10 | return {"msg":"This is first Typescript Microservice"}; 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Chapter09/prometheus-grafana/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){} 7 | 8 | @Get('/') 9 | async get(): Promise { 10 | console.log("called"); 11 | return {"msg":"This is first Typescript Microservice"}; 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter09/prometheus-grafana/src/controllers/MetricsRoute.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Req, Res } from "routing-controllers"; 2 | import { Register } from "../config/metrics-modules/MetricModule"; 3 | 4 | @Controller('/metrics') 5 | export class MetricsRoute{ 6 | 7 | @Get('/') 8 | async getMetrics(@Req() req:any,@Res() res:any):Promise { 9 | res.set('Content-Type', Register.contentType); 10 | res.end(Register.metrics()); 11 | }; 12 | 13 | 14 | } -------------------------------------------------------------------------------- /Chapter09/prometheus-grafana/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter09/prometheus-grafana/src/types.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/TypeScript-Microservices/91aa8e66696971354245c826bc5d23f885e8c27a/Chapter09/prometheus-grafana/src/types.ts -------------------------------------------------------------------------------- /Chapter09/simple-metric/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter09/simple-metric/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter09/simple-metric/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter09/simple-metric/simple-metric.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/TypeScript-Microservices/91aa8e66696971354245c826bc5d23f885e8c27a/Chapter09/simple-metric/simple-metric.rar -------------------------------------------------------------------------------- /Chapter09/simple-metric/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter09/simple-metric/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter09/simple-metric/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | var pmx=require('pmx'); 3 | 4 | @Controller('/hello-world') 5 | export class HelloWorld { 6 | private pmxVar:any; 7 | private probe:any; 8 | private metric:any; 9 | 10 | constructor(){ 11 | this.pmxVar=pmx.init({ 12 | http:true, 13 | errors:true, 14 | custom_probes:true, 15 | network:true, 16 | ports:true 17 | }); 18 | this.probe=this.pmxVar.probe(); 19 | this.metric=this.probe.metric({ 20 | name:'Simple custom metric' 21 | }); 22 | 23 | } 24 | 25 | @Get('/') 26 | async get(): Promise { 27 | this.metric.set(new Date().toISOString()); 28 | return {"msg":"This is first Typescript Microservice"}; 29 | } 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Chapter09/simple-metric/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter09/simple-metric/src/types.ts: -------------------------------------------------------------------------------- 1 | declare module 'pmx'; -------------------------------------------------------------------------------- /Chapter09/user/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter09/user/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter09/user/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter09/user/first-microservice.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/TypeScript-Microservices/91aa8e66696971354245c826bc5d23f885e8c27a/Chapter09/user/first-microservice.rar -------------------------------------------------------------------------------- /Chapter09/user/first-microservice.rar.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/TypeScript-Microservices/91aa8e66696971354245c826bc5d23f885e8c27a/Chapter09/user/first-microservice.rar.txt -------------------------------------------------------------------------------- /Chapter09/user/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter09/user/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter09/user/src/controllers/UserController.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController, Post } from 'routing-controllers'; 2 | 3 | @Controller('/users') 4 | export class UserController { 5 | 6 | constructor(){ 7 | 8 | } 9 | 10 | @Get('/user-by-id/:userId') 11 | async get(userId:string): Promise { 12 | return {"code":200,"userExists":"true"}; 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Chapter09/user/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter09/zipkin/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}\\dist\\Index.js", 13 | "outFiles": [ 14 | "${workspaceFolder}/dist/Index.js" 15 | ] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /Chapter09/zipkin/config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "express":{ 3 | "port":8081, 4 | "debug":5858, 5 | "host":"products-service" 6 | }, 7 | "mongo":{ 8 | "urlClient": "mongodb://127.0.0.1:27017/products" 9 | }, 10 | "loglevel": "info" 11 | } -------------------------------------------------------------------------------- /Chapter09/zipkin/server/zipkin-server-2.7.1-exec.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/TypeScript-Microservices/91aa8e66696971354245c826bc5d23f885e8c27a/Chapter09/zipkin/server/zipkin-server-2.7.1-exec.jar -------------------------------------------------------------------------------- /Chapter09/zipkin/src/Index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './middleware/config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter09/zipkin/src/business-layer/validator/ProductValidationProcessor.ts: -------------------------------------------------------------------------------- 1 | import { validate } from "class-validator"; 2 | import { ProductValidationSchema } from './ProductValidationSchema'; 3 | import { forEach, pick} from 'lodash'; 4 | 5 | async function validateProductRequest(productReqObj:any): Promise{ 6 | let validProductData = new ProductValidationSchema(productReqObj); 7 | let validationResults = await validate(validProductData); 8 | let constraints =[] 9 | if(validationResults && validationResults.length > 0 ){ 10 | forEach(validationResults, (item)=>{ 11 | constraints.push(pick(item, 'constraints', 'property')); 12 | }); 13 | } 14 | return constraints; 15 | } 16 | 17 | 18 | 19 | export {validateProductRequest} -------------------------------------------------------------------------------- /Chapter09/zipkin/src/data-layer/data-abstracts/repositories/IProductDocument.ts: -------------------------------------------------------------------------------- 1 | import mongoose=require('mongoose'); 2 | 3 | export interface IProductDocument extends mongoose.Document{ 4 | id:string, 5 | ownerId:String, 6 | brand:{ 7 | id:number, 8 | name:string 9 | }, 10 | lastUpdated:Date, 11 | createdAt:Date, 12 | name:string, 13 | feedbackEmail:string, 14 | description:string, 15 | category:string, 16 | desc:[{ 17 | lang:string, 18 | val:string 19 | }], 20 | shipping:{ 21 | dimensions:{ 22 | height:number, 23 | width:number, 24 | length:number 25 | }, 26 | weight:number 27 | }, 28 | attrs:[{ 29 | name:string, 30 | value:string 31 | }] 32 | 33 | } -------------------------------------------------------------------------------- /Chapter09/zipkin/src/data-layer/data-abstracts/repositories/ProductRepository.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Model,model } from "mongoose"; 3 | import { MongooseAccess } from "../../../data-layer/adapters/MongoAccess"; 4 | import { IProductDocument } from "../../../data-layer/data-abstracts/repositories/IProductDocument"; 5 | import { ProductSchema } from "../../../data-layer/data-abstracts/repositories/ProductSchema"; 6 | 7 | export type ProductMod = Model; 8 | 9 | export const ProductRepo:ProductMod = MongooseAccess.mongooseConnection.model("product", ProductSchema); 10 | 11 | -------------------------------------------------------------------------------- /Chapter09/zipkin/src/data-layer/data-abstracts/repositories/index.ts: -------------------------------------------------------------------------------- 1 | export {IProductDocument} from './IProductDocument'; 2 | export {ProductRepo} from './ProductRepository'; 3 | export {ProductSchema} from './ProductSchema'; -------------------------------------------------------------------------------- /Chapter09/zipkin/src/middleware/common/Logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter09/zipkin/src/middleware/config/ZipkinConfig.ts: -------------------------------------------------------------------------------- 1 | import {Tracer} from 'zipkin'; 2 | import {BatchRecorder} from 'zipkin'; 3 | import {HttpLogger} from 'zipkin-transport-http'; 4 | const CLSContext = require('zipkin-context-cls'); 5 | 6 | 7 | export const ctxImpl=new CLSContext('typescript-microservices'); 8 | const logRecorder=new BatchRecorder({ 9 | logger:new HttpLogger({ 10 | endpoint:`http://localhost:9411/api/v1/spans` 11 | }) 12 | }) 13 | 14 | export const tracer=new Tracer({ctxImpl:ctxImpl,recorder:logRecorder}); -------------------------------------------------------------------------------- /Chapter09/zipkin/src/middleware/custom-middleware/MyMiddleWare.ts: -------------------------------------------------------------------------------- 1 | import {ExpressMiddlewareInterface} from "routing-controllers"; 2 | 3 | export class MyMiddleware implements ExpressMiddlewareInterface { // interface implementation is optional 4 | 5 | constructor(){} 6 | use(request: any, response: any, next?: (err?: any) => any): any { 7 | console.log("custom middleware gets called."); 8 | next(); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Chapter09/zipkin/src/service-layer/request/IProductRequest.ts: -------------------------------------------------------------------------------- 1 | export interface IProductCreateRequest{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter09/zipkin/src/service-layer/responses/IProductResponse.ts: -------------------------------------------------------------------------------- 1 | export interface IProductResponse{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /Chapter10/auditjs/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter10/auditjs/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter10/auditjs/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter10/auditjs/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter10/auditjs/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter10/auditjs/src/config/Express.ts: -------------------------------------------------------------------------------- 1 | import * as express from 'express'; 2 | import * as cors from 'cors'; 3 | import * as bodyParser from 'body-parser'; 4 | import { useExpressServer } from 'routing-controllers'; 5 | import * as path from 'path'; 6 | 7 | export class ExpressConfig{ 8 | app: express.Express; 9 | constructor() { 10 | this.app = express(); 11 | this.app.use(cors()); 12 | this.app.use(bodyParser.json()); 13 | this.app.use(bodyParser.urlencoded({ extended: false })); 14 | this.setUpControllers(); 15 | } 16 | 17 | setUpControllers(){ 18 | const controllersPath = path.resolve('dist', 'controllers'); 19 | //useExpressServer has lots of options, can be viewed at node_modules\routing-controllers\RoutingControllersOptions.d.ts 20 | useExpressServer(this.app,{ 21 | controllers:[controllersPath+"/*.js"] 22 | }); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Chapter10/auditjs/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"} 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter10/auditjs/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter10/express-lusca/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter10/express-lusca/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter10/express-lusca/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter10/express-lusca/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter10/express-lusca/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter10/express-lusca/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"} 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter10/express-lusca/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter10/rate-limiter/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter10/rate-limiter/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter10/rate-limiter/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter10/rate-limiter/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter10/rate-limiter/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter10/rate-limiter/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"} 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter10/rate-limiter/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter10/safe-regex/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "requires": true, 3 | "lockfileVersion": 1, 4 | "dependencies": { 5 | "ret": { 6 | "version": "0.1.15", 7 | "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", 8 | "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==" 9 | }, 10 | "safe-regex": { 11 | "version": "1.1.0", 12 | "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", 13 | "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", 14 | "requires": { 15 | "ret": "0.1.15" 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter10/safe-regex/safe.js: -------------------------------------------------------------------------------- 1 | let safe=require('safe-regex'); 2 | let regex=process.argv.slice(2).join(' '); 3 | console.log(safe(regex)); 4 | 5 | 6 | //sample tests. 7 | console.log(safe('(x+x+)+y')); 8 | console.log(safe('(beep|boop)*')); 9 | console.log(safe('(a+){10}')); 10 | console.log(safe('\blocation\s*:[^:\n]+\b(Oakland|San Francisco)\b')); 11 | -------------------------------------------------------------------------------- /Chapter10/tslinter/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter10/tslinter/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter10/tslinter/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter10/tslinter/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter10/tslinter/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from "../common/logging"; 2 | import { ExpressConfig } from "./Express"; 3 | 4 | export class Application { 5 | 6 | public server: any; 7 | public express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter10/tslinter/src/config/Express.ts: -------------------------------------------------------------------------------- 1 | import * as bodyParser from "body-parser"; 2 | import * as cors from "cors"; 3 | import * as express from "express"; 4 | import * as path from "path"; 5 | import { useExpressServer } from "routing-controllers"; 6 | 7 | export class ExpressConfig { 8 | public app: express.Express; 9 | constructor() { 10 | this.app = express(); 11 | this.app.use(cors()); 12 | this.app.use(bodyParser.json()); 13 | this.app.use(bodyParser.urlencoded({ extended: false })); 14 | this.setUpControllers(); 15 | } 16 | 17 | public setUpControllers() { 18 | const controllersPath = path.resolve("dist", "controllers"); 19 | //useExpressServer has lots of options, can be viewed at node_modules\routing-controllers\RoutingControllersOptions.d.ts 20 | useExpressServer(this.app, { 21 | controllers: [controllersPath + "/*.js"], 22 | }); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Chapter10/tslinter/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController } from "routing-controllers"; 2 | 3 | @Controller("/hello-world") 4 | export class HelloWorld { 5 | 6 | constructor() { 7 | 8 | } 9 | @Get("/") 10 | public async get(): Promise { 11 | return {msg: "This is first Typescript Microservice"}; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Chapter10/tslinter/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /Chapter10/tslinter/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": [ 4 | "tslint:recommended" 5 | ], 6 | "jsRules": {}, 7 | "rules": { 8 | "no-banned-terms": true, 9 | "no-delete-expression": true, 10 | "no-document-domain": true, 11 | "no-disable-auto-sanitization": true, 12 | "no-duplicate-parameter-names": true, 13 | "no-exec-script": true, 14 | "no-function-constructor-with-string-args": true, 15 | "no-octal-literal": true, 16 | "no-reserved-keywords": true, 17 | "no-string-based-set-immediate": true, 18 | "no-string-based-set-interval": true, 19 | "no-string-based-set-timeout": true, 20 | "no-duplicate-key": true, 21 | "no-eval": true, 22 | "use-strict": true 23 | }, 24 | "rulesDirectory": [] 25 | } -------------------------------------------------------------------------------- /Chapter10/typescript-express-session/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log -------------------------------------------------------------------------------- /Chapter10/typescript-express-session/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/dist/bin/www.js", 12 | "smartStep": true, 13 | "outFiles": [ 14 | "../dist/**/*.js" 15 | ], 16 | "protocol": "inspector" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Chapter10/typescript-express-session/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | 8 | #install depedencies 9 | COPY package.json /usr/src/app 10 | RUN npm install 11 | 12 | #bundle app src 13 | COPY . /usr/src/app 14 | 15 | CMD [ "npm" , "start" ] -------------------------------------------------------------------------------- /Chapter10/typescript-express-session/src/common/logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /Chapter10/typescript-express-session/src/config/Application.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '../common/logging'; 2 | import { ExpressConfig } from './Express'; 3 | 4 | export class Application { 5 | 6 | server: any; 7 | express: ExpressConfig; 8 | 9 | constructor() { 10 | this.express = new ExpressConfig(); 11 | 12 | const port = 3000; 13 | this.server = this.express.app.listen(port, () => { 14 | logger.info(`Server Started! Express: http://localhost:${port}`); 15 | }); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Chapter10/typescript-express-session/src/controllers/HelloWorld.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, JsonController } from 'routing-controllers'; 2 | 3 | @Controller('/hello-world') 4 | export class HelloWorld { 5 | 6 | constructor(){ 7 | 8 | } 9 | @Get('/') 10 | async get(): Promise { 11 | return {"msg":"This is first Typescript Microservice"} 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter10/typescript-express-session/src/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}\\dist\\Index.js", 13 | "outFiles": [ 14 | "${workspaceFolder}/dist/Index.js" 15 | ] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/Dockerfile: -------------------------------------------------------------------------------- 1 | #LATEST NODE Version -which node version u will use. 2 | FROM node:9.2.0 3 | 4 | # Create app directory 5 | RUN mkdir -p /usr/src/app 6 | WORKDIR /usr/src/app 7 | #install dependencies 8 | COPY package.json /usr/src/app 9 | RUN npm install 10 | #bundle app src 11 | COPY . /usr/src/app 12 | EXPOSE 3000 13 | CMD [ "npm" , "start" ] 14 | -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "express":{ 3 | "port":8081, 4 | "debug":5858, 5 | "host":"products-service" 6 | }, 7 | "mongo":{ 8 | "urlClient": "mongodb://127.0.0.1:27017/products" 9 | }, 10 | "loglevel": "info" 11 | } -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | app: 4 | container_name: app 5 | build: ./ 6 | restart: always 7 | ports: 8 | - "3000:8081" 9 | links: 10 | - mongo 11 | mongo: 12 | container_name: mongo 13 | image: mongo 14 | volumes: 15 | - ./data:/data/db 16 | ports: 17 | - "27017:27017" 18 | -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/products-catalog -with-docker.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/TypeScript-Microservices/91aa8e66696971354245c826bc5d23f885e8c27a/shopping cart microservices/products-catalog -with-docker/products-catalog -with-docker.rar -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/src/Index.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | //reflect-metadata shim is required, requirement of routing-controllers module. 3 | import 'reflect-metadata'; 4 | import { Application } from './middleware/config/Application'; 5 | 6 | export default new Application(); -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/src/business-layer/validator/ProductValidationProcessor.ts: -------------------------------------------------------------------------------- 1 | import { validate } from "class-validator"; 2 | import { ProductValidationSchema } from './ProductValidationSchema'; 3 | import { forEach, pick} from 'lodash'; 4 | 5 | async function validateProductRequest(productReqObj:any): Promise{ 6 | let validProductData = new ProductValidationSchema(productReqObj); 7 | let validationResults = await validate(validProductData); 8 | let constraints =[] 9 | if(validationResults && validationResults.length > 0 ){ 10 | forEach(validationResults, (item)=>{ 11 | constraints.push(pick(item, 'constraints', 'property')); 12 | }); 13 | } 14 | return constraints; 15 | } 16 | 17 | 18 | 19 | export {validateProductRequest} -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/src/data-layer/data-abstracts/repositories/IProductDocument.ts: -------------------------------------------------------------------------------- 1 | import mongoose=require('mongoose'); 2 | 3 | export interface IProductDocument extends mongoose.Document{ 4 | id:string, 5 | ownerId:String, 6 | brand:{ 7 | id:number, 8 | name:string 9 | }, 10 | lastUpdated:Date, 11 | createdAt:Date, 12 | name:string, 13 | feedbackEmail:string, 14 | description:string, 15 | category:string, 16 | desc:[{ 17 | lang:string, 18 | val:string 19 | }], 20 | shipping:{ 21 | dimensions:{ 22 | height:number, 23 | width:number, 24 | length:number 25 | }, 26 | weight:number 27 | }, 28 | attrs:[{ 29 | name:string, 30 | value:string 31 | }] 32 | 33 | } -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/src/data-layer/data-abstracts/repositories/ProductRepository.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Model,model } from "mongoose"; 3 | import { MongooseAccess } from "../../../data-layer/adapters/MongoAccess"; 4 | import { IProductDocument } from "../../../data-layer/data-abstracts/repositories/IProductDocument"; 5 | import { ProductSchema } from "../../../data-layer/data-abstracts/repositories/ProductSchema"; 6 | 7 | export type ProductMod = Model; 8 | 9 | export const ProductRepo:ProductMod = MongooseAccess.mongooseConnection.model("product", ProductSchema); 10 | 11 | -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/src/data-layer/data-abstracts/repositories/index.ts: -------------------------------------------------------------------------------- 1 | export {IProductDocument} from './IProductDocument'; 2 | export {ProductRepo} from './ProductRepository'; 3 | export {ProductSchema} from './ProductSchema'; -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/src/middleware/common/Logging.ts: -------------------------------------------------------------------------------- 1 | import * as winston from 'winston'; 2 | 3 | export const logger = new winston.Logger(); 4 | 5 | const env = 'development'; 6 | 7 | // Development Logger 8 | if(env === 'development') { 9 | logger.add(winston.transports.Console, { 10 | type: 'verbose', 11 | colorize: true, 12 | prettyPrint: true, 13 | handleExceptions: true, 14 | humanReadableUnhandledException: true 15 | }); 16 | } 17 | 18 | process.on('unhandledRejection', function (reason, p) { 19 | logger.warn('system level exceptions at, Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason); 20 | }); 21 | -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/src/middleware/custom-middleware/MyMiddleWare.ts: -------------------------------------------------------------------------------- 1 | import {ExpressMiddlewareInterface} from "routing-controllers"; 2 | 3 | export class MyMiddleware implements ExpressMiddlewareInterface { // interface implementation is optional 4 | 5 | constructor(){} 6 | use(request: any, response: any, next?: (err?: any) => any): any { 7 | console.log("custom middleware gets called."); 8 | next(); 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/src/service-layer/request/IProductRequest.ts: -------------------------------------------------------------------------------- 1 | export interface IProductCreateRequest{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } -------------------------------------------------------------------------------- /shopping cart microservices/products-catalog -with-docker/src/service-layer/responses/IProductResponse.ts: -------------------------------------------------------------------------------- 1 | export interface IProductResponse{ 2 | ownerId:String, 3 | brand:{ 4 | id:number, 5 | name:string 6 | }, 7 | lastUpdated:Date, 8 | createdAt:Date, 9 | name:string, 10 | feedbackEmail:string, 11 | description:string, 12 | category:string, 13 | desc:[{ 14 | lang:string, 15 | value:string 16 | }], 17 | shipping:{ 18 | dimensions:{ 19 | height:number, 20 | width:number, 21 | length:number 22 | }, 23 | weight:number 24 | }, 25 | attrs:[{ 26 | name:string, 27 | value:string 28 | }] 29 | } --------------------------------------------------------------------------------