ThearticleSwagger,NodeJS,&TypeScript:TSOA,hasadeeperreviewofhowthisapplicationisconstructed.Thisback-endapplicationisapartofalargerefforttodemonstratetheprincipalsofwebdevelopmentexpressedinthearticlePracticalWebDevelopmentandArchitecture.Advocatingtheprincipal"aseparationofconcerns",thincontrollersresidinginthe"service-layer"retainthesingularpurposeofactingasfiltersforAPIrequest.Controllersexisttosupportresultsofdataprocessinglogicderivedinoutsidelayersofconcern.Maximizingtheopportunityforapplicationgrowth,withoutextensiverefactoring,theprocessingofbusinessrulesandcross-cuttingconcernsareplacedinthe"business-layer",whiledatabaseadapters,formalizeddatabasequeries,andservicesusedtoabstractthosequeriesarestationedinthe"data-layer".Asmuchaspossiblethecontrollersdutiesarefocusedondirectingrequesttooutsideresourcesandrespondingtoresultsfromthoseresourcewithsimpleconditionallogic.
AnotheraspectemphasizedinthePracticalWebDevelopmentandArchitecturearticleistheimportanceofadoptingstrategiestosupportoptimaloutputfromadevelopmentteam.Tothisendtsoa,aSwaggerUIcreationtool,isusedtodemonstrateaninnovativemeansofgeneratinganAPItestingportalanddocumentationbasedonafewsimplestructuralrequirements.TheSwaggerscaffoldingresidesinthe"presentation-layer".
ws-dev-docker-example:istherepositoryusedtobundlethisapplicationalongwiththreeothersubmodules.DockercomposeisusedtoorchestratethedevelopmentofaFullStack.ThosesubmodulesarelocatedintheGitHubrepositorieslistedbelow.
(thisrepo)ws-node-demows-mongo-demows-nginx-demows-ngx-login-demoHowthesecontainersareusedasabundletofacilitateaFullStackapproachfordevelopingwithDockerisdelineatedinthearticle,Dockerismy{I.D.E}
Itshouldbenotedthatthisapplicationiscreatedforthepurposesofdemonstratingadevelopmentparadigm,notasaproductionreadyseed.
Althoughtheapplicationisbestunderstoodasapartofthelargeroveralleffortdemonstratedwiththews-dev-docker-example,itcanstillbeclonedandstoodupwithouttheuseoftheDockerbundle.Tousethisapplicationasaseparatestandaloneentity,usethelocal-clientbranch.
WaystoconstructthisapplicationwithorwithoutDockerUsingtheFullStack(ThisNodeJsapp,Mongo,NGINX,Angularapp)approachwithanintegratedDockerenvironment.
Gotothews-dev-docker-examplerepoandfollowtheREADME.mdUsingDockertostanduptheapplicationwithadependencyofMongo
$>gitfetch$>gitcheckoutorigin/serverless$>docker-composeupSwaggerUIAPItesterhttps://localhost:8080/docsBareMetal(Installinglibrariesandrunningitonyourmachine'sOS)
InstallMongoDBonyourmachine.MongoDBOSXEditionMongoDBWindowsEdition$>gitfetch$>gitcheckoutorigin/local-client$>npminstallBeforrunningtheapplication,youwillneedtoupdatethesrc/data-layer/adapters/MongooseAccess.tsfilebyswitchingcommentedoutline21and22.
from
//letconnectionString=config.get('mongo.urlClient').toString();letconnectionString=config.get('mongo.urlDocker').toString();to
letconnectionString=config.get('mongo.urlClient').toString();//letconnectionString=config.get('mongo.urlDocker').toString();Makingthischangewillswitchthehostfromws-mongo-demoto127.0.0.1(localhost).Thesevariablesaresetintheconfig/default.yaml
$>npmrunstartSwaggerUIAPItesterhttps://localhost:8080/docsHerearesomeexamplesofobjecttypestoinsertanincorrectuserandacorrectuser{"username":"tao","password":"1234","firstname":"zip","lastname":"zap","email":"zip-zap@ez.com","admin":false,"isLoggedIn":false}correctuser{"username":"taosing","password":"password","firstname":"fifty","lastname":"cents","email":"zip-zap@ez.com","admin":false,"isLoggedIn":false}
评论