├── README.md ├── coverage ├── coverage.json ├── lcov-report │ ├── base.css │ ├── index.html │ ├── lib │ │ ├── builder.js.html │ │ ├── index.html │ │ ├── init_server.js.html │ │ └── warn.js.html │ ├── prettify.css │ ├── prettify.js │ ├── sort-arrow-sprite.png │ └── sorter.js └── lcov.info ├── index.js ├── lib ├── builder.js └── logger.js ├── package.json ├── simple-restify.png └── test ├── builder.test.js └── integration ├── routes ├── health.js └── withParams.js └── server.test.js /README.md: -------------------------------------------------------------------------------- 1 | ![alt tag](https://github.com/ttaub/simple-restify/blob/master/simple-restify.png?raw=true) 2 | 3 | Hassle free server creation. No point in recreating the same thing when we can have one standard server. 4 | 5 | ### What is this repository for? ### 6 | 7 | * Creating Restify servers. 8 | 9 | ### How do I get set up? ### 10 | 11 | Everything is created using the builder object. In order to use the builder object you should require common-server: 12 | 13 | var Builder = require( 'simple-restify' ); 14 | 15 | The Builder object has 3 functions: 16 | 17 | var server = Builder 18 | .config( config ) //add the server configurations from a json object 19 | .routesOptions( options ) //accepts json object that will be passed into all the routes 20 | .add( function( server ){ //allows you to add your own custom functions which need server 21 | 22 | return server; 23 | 24 | }) 25 | .run(); //runs the server and returns the server json object 26 | 27 | The config json has the following properties you can add: 28 | 29 | { 30 | "port" : 8000, 31 | "name" : "sample-server", 32 | "version" : 1.0.0, 33 | "logging" : true, 34 | "rootPath" : "/users/test", 35 | "routesPath" : "/users/test/routes/" 36 | } 37 | -------------------------------------------------------------------------------- /coverage/coverage.json: -------------------------------------------------------------------------------- 1 | {"/Users/tomt/Projects/jeeko/common-server/lib/builder.js":{"path":"/Users/tomt/Projects/jeeko/common-server/lib/builder.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":3,"9":3,"10":3,"11":3,"12":3,"13":3,"14":3,"15":3,"16":3,"17":3,"18":3,"19":3,"20":3,"21":3,"22":3,"23":3,"24":3,"25":3,"26":1,"27":1,"28":1,"29":2,"30":2,"31":2,"32":0,"33":2,"34":2,"35":1,"36":0,"37":0,"38":0,"39":1,"40":1,"41":1,"42":1,"43":0,"44":0,"45":1,"46":3,"47":1,"48":1},"b":{"1":[3,0],"2":[3,0],"3":[3,0],"4":[3,0],"5":[3,0],"6":[3,0],"7":[3,3],"8":[3,0],"9":[3,2],"10":[3,3],"11":[3,3],"12":[0,2],"13":[0,0],"14":[0,0],"15":[0,0]},"f":{"1":3,"2":1,"3":2,"4":2,"5":0,"6":1,"7":0,"8":3},"fnMap":{"1":{"name":"ServerObject","line":17,"loc":{"start":{"line":17,"column":0},"end":{"line":17,"column":59}}},"2":{"name":"valueHandlers","line":65,"loc":{"start":{"line":65,"column":0},"end":{"line":65,"column":41}}},"3":{"name":"(anonymous_3)","line":69,"loc":{"start":{"line":69,"column":18},"end":{"line":69,"column":35}}},"4":{"name":"(anonymous_4)","line":73,"loc":{"start":{"line":73,"column":56},"end":{"line":73,"column":71}}},"5":{"name":"(anonymous_5)","line":83,"loc":{"start":{"line":83,"column":36},"end":{"line":83,"column":61}}},"6":{"name":"(anonymous_6)","line":90,"loc":{"start":{"line":90,"column":38},"end":{"line":90,"column":57}}},"7":{"name":"(anonymous_7)","line":96,"loc":{"start":{"line":96,"column":29},"end":{"line":96,"column":40}}},"8":{"name":"create","line":102,"loc":{"start":{"line":102,"column":0},"end":{"line":102,"column":47}}}},"statementMap":{"1":{"start":{"line":4,"column":0},"end":{"line":4,"column":28}},"2":{"start":{"line":5,"column":0},"end":{"line":5,"column":31}},"3":{"start":{"line":6,"column":0},"end":{"line":6,"column":41}},"4":{"start":{"line":7,"column":0},"end":{"line":7,"column":46}},"5":{"start":{"line":8,"column":0},"end":{"line":8,"column":42}},"6":{"start":{"line":11,"column":0},"end":{"line":14,"column":6}},"7":{"start":{"line":17,"column":0},"end":{"line":63,"column":1}},"8":{"start":{"line":21,"column":1},"end":{"line":21,"column":26}},"9":{"start":{"line":23,"column":1},"end":{"line":26,"column":2}},"10":{"start":{"line":25,"column":2},"end":{"line":25,"column":48}},"11":{"start":{"line":30,"column":1},"end":{"line":30,"column":18}},"12":{"start":{"line":31,"column":1},"end":{"line":31,"column":22}},"13":{"start":{"line":32,"column":1},"end":{"line":32,"column":24}},"14":{"start":{"line":36,"column":1},"end":{"line":36,"column":63}},"15":{"start":{"line":38,"column":1},"end":{"line":44,"column":2}},"16":{"start":{"line":41,"column":2},"end":{"line":41,"column":36}},"17":{"start":{"line":42,"column":2},"end":{"line":42,"column":45}},"18":{"start":{"line":48,"column":1},"end":{"line":48,"column":65}},"19":{"start":{"line":50,"column":1},"end":{"line":56,"column":2}},"20":{"start":{"line":52,"column":2},"end":{"line":52,"column":46}},"21":{"start":{"line":53,"column":2},"end":{"line":53,"column":46}},"22":{"start":{"line":54,"column":2},"end":{"line":54,"column":55}},"23":{"start":{"line":60,"column":1},"end":{"line":60,"column":31}},"24":{"start":{"line":61,"column":1},"end":{"line":61,"column":31}},"25":{"start":{"line":62,"column":1},"end":{"line":62,"column":40}},"26":{"start":{"line":65,"column":0},"end":{"line":81,"column":1}},"27":{"start":{"line":67,"column":1},"end":{"line":67,"column":30}},"28":{"start":{"line":69,"column":2},"end":{"line":80,"column":4}},"29":{"start":{"line":71,"column":3},"end":{"line":71,"column":43}},"30":{"start":{"line":73,"column":3},"end":{"line":79,"column":3}},"31":{"start":{"line":75,"column":3},"end":{"line":76,"column":39}},"32":{"start":{"line":75,"column":15},"end":{"line":75,"column":42}},"33":{"start":{"line":76,"column":10},"end":{"line":76,"column":37}},"34":{"start":{"line":78,"column":3},"end":{"line":78,"column":15}},"35":{"start":{"line":83,"column":0},"end":{"line":88,"column":1}},"36":{"start":{"line":85,"column":1},"end":{"line":85,"column":46}},"37":{"start":{"line":86,"column":1},"end":{"line":86,"column":50}},"38":{"start":{"line":87,"column":1},"end":{"line":87,"column":55}},"39":{"start":{"line":90,"column":0},"end":{"line":94,"column":1}},"40":{"start":{"line":92,"column":1},"end":{"line":92,"column":29}},"41":{"start":{"line":93,"column":1},"end":{"line":93,"column":13}},"42":{"start":{"line":96,"column":0},"end":{"line":100,"column":1}},"43":{"start":{"line":98,"column":1},"end":{"line":98,"column":8}},"44":{"start":{"line":99,"column":1},"end":{"line":99,"column":22}},"45":{"start":{"line":102,"column":0},"end":{"line":105,"column":1}},"46":{"start":{"line":104,"column":1},"end":{"line":104,"column":56}},"47":{"start":{"line":108,"column":0},"end":{"line":108,"column":38}},"48":{"start":{"line":110,"column":0},"end":{"line":114,"column":2}}},"branchMap":{"1":{"line":23,"type":"if","locations":[{"start":{"line":23,"column":1},"end":{"line":23,"column":1}},{"start":{"line":23,"column":1},"end":{"line":23,"column":1}}]},"2":{"line":38,"type":"if","locations":[{"start":{"line":38,"column":1},"end":{"line":38,"column":1}},{"start":{"line":38,"column":1},"end":{"line":38,"column":1}}]},"3":{"line":41,"type":"binary-expr","locations":[{"start":{"line":41,"column":14},"end":{"line":41,"column":22}},{"start":{"line":41,"column":26},"end":{"line":41,"column":35}}]},"4":{"line":42,"type":"binary-expr","locations":[{"start":{"line":42,"column":17},"end":{"line":42,"column":28}},{"start":{"line":42,"column":32},"end":{"line":42,"column":44}}]},"5":{"line":50,"type":"if","locations":[{"start":{"line":50,"column":1},"end":{"line":50,"column":1}},{"start":{"line":50,"column":1},"end":{"line":50,"column":1}}]},"6":{"line":52,"type":"binary-expr","locations":[{"start":{"line":52,"column":14},"end":{"line":52,"column":32}},{"start":{"line":52,"column":36},"end":{"line":52,"column":45}}]},"7":{"line":53,"type":"binary-expr","locations":[{"start":{"line":53,"column":14},"end":{"line":53,"column":32}},{"start":{"line":53,"column":36},"end":{"line":53,"column":45}}]},"8":{"line":54,"type":"binary-expr","locations":[{"start":{"line":54,"column":17},"end":{"line":54,"column":38}},{"start":{"line":54,"column":42},"end":{"line":54,"column":54}}]},"9":{"line":60,"type":"binary-expr","locations":[{"start":{"line":60,"column":13},"end":{"line":60,"column":17}},{"start":{"line":60,"column":21},"end":{"line":60,"column":30}}]},"10":{"line":61,"type":"binary-expr","locations":[{"start":{"line":61,"column":13},"end":{"line":61,"column":17}},{"start":{"line":61,"column":21},"end":{"line":61,"column":30}}]},"11":{"line":62,"type":"binary-expr","locations":[{"start":{"line":62,"column":16},"end":{"line":62,"column":23}},{"start":{"line":62,"column":27},"end":{"line":62,"column":39}}]},"12":{"line":75,"type":"if","locations":[{"start":{"line":75,"column":3},"end":{"line":75,"column":3}},{"start":{"line":75,"column":3},"end":{"line":75,"column":3}}]},"13":{"line":85,"type":"binary-expr","locations":[{"start":{"line":85,"column":13},"end":{"line":85,"column":37}},{"start":{"line":85,"column":41},"end":{"line":85,"column":45}}]},"14":{"line":86,"type":"binary-expr","locations":[{"start":{"line":86,"column":13},"end":{"line":86,"column":37}},{"start":{"line":86,"column":41},"end":{"line":86,"column":49}}]},"15":{"line":87,"type":"binary-expr","locations":[{"start":{"line":87,"column":16},"end":{"line":87,"column":43}},{"start":{"line":87,"column":47},"end":{"line":87,"column":54}}]}}},"/Users/tomt/Projects/jeeko/common-server/lib/warn.js":{"path":"/Users/tomt/Projects/jeeko/common-server/lib/warn.js","s":{"1":1,"2":1,"3":1,"4":1,"5":0,"6":0,"7":0,"8":0,"9":1},"b":{"1":[0,0],"2":[0,0]},"f":{"1":0},"fnMap":{"1":{"name":"warn","line":9,"loc":{"start":{"line":9,"column":0},"end":{"line":9,"column":16}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":3,"column":37}},"2":{"start":{"line":5,"column":0},"end":{"line":5,"column":46}},"3":{"start":{"line":7,"column":0},"end":{"line":7,"column":49}},"4":{"start":{"line":9,"column":0},"end":{"line":20,"column":1}},"5":{"start":{"line":11,"column":1},"end":{"line":14,"column":2}},"6":{"start":{"line":13,"column":2},"end":{"line":13,"column":74}},"7":{"start":{"line":16,"column":1},"end":{"line":19,"column":2}},"8":{"start":{"line":18,"column":2},"end":{"line":18,"column":76}},"9":{"start":{"line":22,"column":0},"end":{"line":22,"column":22}}},"branchMap":{"1":{"line":11,"type":"if","locations":[{"start":{"line":11,"column":1},"end":{"line":11,"column":1}},{"start":{"line":11,"column":1},"end":{"line":11,"column":1}}]},"2":{"line":16,"type":"if","locations":[{"start":{"line":16,"column":1},"end":{"line":16,"column":1}},{"start":{"line":16,"column":1},"end":{"line":16,"column":1}}]}}},"/Users/tomt/Projects/jeeko/common-server/lib/init_server.js":{"path":"/Users/tomt/Projects/jeeko/common-server/lib/init_server.js","s":{"1":1,"2":1,"3":1,"4":0,"5":0,"6":0,"7":1,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":1,"32":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0},"fnMap":{"1":{"name":"includeRoutes","line":7,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":44}}},"2":{"name":"(anonymous_2)","line":9,"loc":{"start":{"line":9,"column":38},"end":{"line":9,"column":56}}},"3":{"name":"startServer","line":21,"loc":{"start":{"line":21,"column":0},"end":{"line":21,"column":30}}},"4":{"name":"(anonymous_4)","line":60,"loc":{"start":{"line":60,"column":14},"end":{"line":60,"column":40}}},"5":{"name":"(anonymous_5)","line":71,"loc":{"start":{"line":71,"column":32},"end":{"line":71,"column":64}}},"6":{"name":"(anonymous_6)","line":81,"loc":{"start":{"line":81,"column":29},"end":{"line":81,"column":40}}},"7":{"name":"(anonymous_7)","line":88,"loc":{"start":{"line":88,"column":17},"end":{"line":88,"column":36}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":3,"column":46}},"2":{"start":{"line":5,"column":0},"end":{"line":5,"column":25}},"3":{"start":{"line":7,"column":0},"end":{"line":18,"column":1}},"4":{"start":{"line":9,"column":1},"end":{"line":16,"column":4}},"5":{"start":{"line":11,"column":2},"end":{"line":14,"column":3}},"6":{"start":{"line":13,"column":3},"end":{"line":13,"column":76}},"7":{"start":{"line":21,"column":0},"end":{"line":86,"column":1}},"8":{"start":{"line":23,"column":1},"end":{"line":23,"column":29}},"9":{"start":{"line":26,"column":1},"end":{"line":26,"column":36}},"10":{"start":{"line":29,"column":1},"end":{"line":29,"column":42}},"11":{"start":{"line":32,"column":1},"end":{"line":32,"column":36}},"12":{"start":{"line":34,"column":1},"end":{"line":34,"column":38}},"13":{"start":{"line":36,"column":1},"end":{"line":44,"column":2}},"14":{"start":{"line":38,"column":2},"end":{"line":42,"column":5}},"15":{"start":{"line":46,"column":1},"end":{"line":52,"column":2}},"16":{"start":{"line":48,"column":2},"end":{"line":51,"column":5}},"17":{"start":{"line":55,"column":1},"end":{"line":55,"column":37}},"18":{"start":{"line":56,"column":1},"end":{"line":56,"column":55}},"19":{"start":{"line":58,"column":1},"end":{"line":68,"column":2}},"20":{"start":{"line":60,"column":2},"end":{"line":66,"column":5}},"21":{"start":{"line":63,"column":3},"end":{"line":63,"column":37}},"22":{"start":{"line":65,"column":3},"end":{"line":65,"column":17}},"23":{"start":{"line":71,"column":1},"end":{"line":76,"column":4}},"24":{"start":{"line":73,"column":2},"end":{"line":73,"column":70}},"25":{"start":{"line":73,"column":26},"end":{"line":73,"column":68}},"26":{"start":{"line":75,"column":2},"end":{"line":75,"column":71}},"27":{"start":{"line":78,"column":1},"end":{"line":78,"column":59}},"28":{"start":{"line":81,"column":1},"end":{"line":84,"column":4}},"29":{"start":{"line":83,"column":2},"end":{"line":83,"column":88}},"30":{"start":{"line":83,"column":26},"end":{"line":83,"column":87}},"31":{"start":{"line":88,"column":0},"end":{"line":91,"column":1}},"32":{"start":{"line":90,"column":1},"end":{"line":90,"column":23}}},"branchMap":{"1":{"line":11,"type":"if","locations":[{"start":{"line":11,"column":2},"end":{"line":11,"column":2}},{"start":{"line":11,"column":2},"end":{"line":11,"column":2}}]},"2":{"line":36,"type":"if","locations":[{"start":{"line":36,"column":1},"end":{"line":36,"column":1}},{"start":{"line":36,"column":1},"end":{"line":36,"column":1}}]},"3":{"line":46,"type":"if","locations":[{"start":{"line":46,"column":1},"end":{"line":46,"column":1}},{"start":{"line":46,"column":1},"end":{"line":46,"column":1}}]},"4":{"line":58,"type":"if","locations":[{"start":{"line":58,"column":1},"end":{"line":58,"column":1}},{"start":{"line":58,"column":1},"end":{"line":58,"column":1}}]},"5":{"line":73,"type":"if","locations":[{"start":{"line":73,"column":2},"end":{"line":73,"column":2}},{"start":{"line":73,"column":2},"end":{"line":73,"column":2}}]},"6":{"line":75,"type":"binary-expr","locations":[{"start":{"line":75,"column":40},"end":{"line":75,"column":54}},{"start":{"line":75,"column":58},"end":{"line":75,"column":65}}]},"7":{"line":83,"type":"if","locations":[{"start":{"line":83,"column":2},"end":{"line":83,"column":2}},{"start":{"line":83,"column":2},"end":{"line":83,"column":2}}]}}}} -------------------------------------------------------------------------------- /coverage/lcov-report/base.css: -------------------------------------------------------------------------------- 1 | body, html { 2 | margin:0; padding: 0; 3 | } 4 | body { 5 | font-family: Helvetica Neue, Helvetica,Arial; 6 | font-size: 10pt; 7 | } 8 | div.header, div.footer { 9 | background: #eee; 10 | padding: 1em; 11 | } 12 | div.header { 13 | z-index: 100; 14 | position: fixed; 15 | top: 0; 16 | border-bottom: 1px solid #666; 17 | width: 100%; 18 | } 19 | div.footer { 20 | border-top: 1px solid #666; 21 | } 22 | div.body { 23 | margin-top: 10em; 24 | } 25 | div.meta { 26 | font-size: 90%; 27 | text-align: center; 28 | } 29 | h1, h2, h3 { 30 | font-weight: normal; 31 | } 32 | h1 { 33 | font-size: 12pt; 34 | } 35 | h2 { 36 | font-size: 10pt; 37 | } 38 | pre { 39 | font-family: Consolas, Menlo, Monaco, monospace; 40 | margin: 0; 41 | padding: 0; 42 | line-height: 14px; 43 | font-size: 14px; 44 | -moz-tab-size: 2; 45 | -o-tab-size: 2; 46 | tab-size: 2; 47 | } 48 | 49 | div.path { font-size: 110%; } 50 | div.path a:link, div.path a:visited { color: #000; } 51 | table.coverage { border-collapse: collapse; margin:0; padding: 0 } 52 | 53 | table.coverage td { 54 | margin: 0; 55 | padding: 0; 56 | color: #111; 57 | vertical-align: top; 58 | } 59 | table.coverage td.line-count { 60 | width: 50px; 61 | text-align: right; 62 | padding-right: 5px; 63 | } 64 | table.coverage td.line-coverage { 65 | color: #777 !important; 66 | text-align: right; 67 | border-left: 1px solid #666; 68 | border-right: 1px solid #666; 69 | } 70 | 71 | table.coverage td.text { 72 | } 73 | 74 | table.coverage td span.cline-any { 75 | display: inline-block; 76 | padding: 0 5px; 77 | width: 40px; 78 | } 79 | table.coverage td span.cline-neutral { 80 | background: #eee; 81 | } 82 | table.coverage td span.cline-yes { 83 | background: #b5d592; 84 | color: #999; 85 | } 86 | table.coverage td span.cline-no { 87 | background: #fc8c84; 88 | } 89 | 90 | .cstat-yes { color: #111; } 91 | .cstat-no { background: #fc8c84; color: #111; } 92 | .fstat-no { background: #ffc520; color: #111 !important; } 93 | .cbranch-no { background: yellow !important; color: #111; } 94 | 95 | .cstat-skip { background: #ddd; color: #111; } 96 | .fstat-skip { background: #ddd; color: #111 !important; } 97 | .cbranch-skip { background: #ddd !important; color: #111; } 98 | 99 | .missing-if-branch { 100 | display: inline-block; 101 | margin-right: 10px; 102 | position: relative; 103 | padding: 0 4px; 104 | background: black; 105 | color: yellow; 106 | } 107 | 108 | .skip-if-branch { 109 | display: none; 110 | margin-right: 10px; 111 | position: relative; 112 | padding: 0 4px; 113 | background: #ccc; 114 | color: white; 115 | } 116 | 117 | .missing-if-branch .typ, .skip-if-branch .typ { 118 | color: inherit !important; 119 | } 120 | 121 | .entity, .metric { font-weight: bold; } 122 | .metric { display: inline-block; border: 1px solid #333; padding: 0.3em; background: white; } 123 | .metric small { font-size: 80%; font-weight: normal; color: #666; } 124 | 125 | div.coverage-summary table { border-collapse: collapse; margin: 3em; font-size: 110%; } 126 | div.coverage-summary td, div.coverage-summary table th { margin: 0; padding: 0.25em 1em; border-top: 1px solid #666; border-bottom: 1px solid #666; } 127 | div.coverage-summary th { text-align: left; border: 1px solid #666; background: #eee; font-weight: normal; } 128 | div.coverage-summary th.file { border-right: none !important; } 129 | div.coverage-summary th.pic { border-left: none !important; text-align: right; } 130 | div.coverage-summary th.pct { border-right: none !important; } 131 | div.coverage-summary th.abs { border-left: none !important; text-align: right; } 132 | div.coverage-summary td.pct { text-align: right; border-left: 1px solid #666; } 133 | div.coverage-summary td.abs { text-align: right; font-size: 90%; color: #444; border-right: 1px solid #666; } 134 | div.coverage-summary td.file { border-left: 1px solid #666; white-space: nowrap; } 135 | div.coverage-summary td.pic { min-width: 120px !important; } 136 | div.coverage-summary a:link { text-decoration: none; color: #000; } 137 | div.coverage-summary a:visited { text-decoration: none; color: #777; } 138 | div.coverage-summary a:hover { text-decoration: underline; } 139 | div.coverage-summary tfoot td { border-top: 1px solid #666; } 140 | 141 | div.coverage-summary .sorter { 142 | height: 10px; 143 | width: 7px; 144 | display: inline-block; 145 | margin-left: 0.5em; 146 | background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; 147 | } 148 | div.coverage-summary .sorted .sorter { 149 | background-position: 0 -20px; 150 | } 151 | div.coverage-summary .sorted-desc .sorter { 152 | background-position: 0 -10px; 153 | } 154 | 155 | .high { background: #b5d592 !important; } 156 | .medium { background: #ffe87c !important; } 157 | .low { background: #fc8c84 !important; } 158 | 159 | span.cover-fill, span.cover-empty { 160 | display:inline-block; 161 | border:1px solid #444; 162 | background: white; 163 | height: 12px; 164 | } 165 | span.cover-fill { 166 | background: #ccc; 167 | border-right: 1px solid #444; 168 | } 169 | span.cover-empty { 170 | background: white; 171 | border-left: none; 172 | } 173 | span.cover-full { 174 | border-right: none !important; 175 | } 176 | pre.prettyprint { 177 | border: none !important; 178 | padding: 0 !important; 179 | margin: 0 !important; 180 | } 181 | .com { color: #999 !important; } 182 | .ignore-none { color: #999; font-weight: normal; } 183 | -------------------------------------------------------------------------------- /coverage/lcov-report/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for All files 5 | 6 | 7 | 8 | 13 | 14 | 15 |
16 |

Code coverage report for All files

17 |

18 | Statements: 58.43% (52 / 89)      19 | Branches: 33.33% (16 / 48)      20 | Functions: 37.5% (6 / 16)      21 | Lines: 60.47% (52 / 86)      22 | Ignored: none      23 |

24 |
25 |
26 |
27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
FileStatementsBranchesFunctionsLines
lib/58.43%(52 / 89)33.33%(16 / 48)37.5%(6 / 16)60.47%(52 / 86)
58 |
59 |
60 | 63 | 64 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /coverage/lcov-report/lib/builder.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for lib/builder.js 5 | 6 | 7 | 8 | 13 | 14 | 15 |
16 |

Code coverage report for lib/builder.js

17 |

18 | Statements: 87.5% (42 / 48)      19 | Branches: 53.33% (16 / 30)      20 | Functions: 75% (6 / 8)      21 | Lines: 89.36% (42 / 47)      22 | Ignored: none      23 |

24 |
All files » lib/ » builder.js
25 |
26 |
27 |

 28 | 
413 | 
1 29 | 2 30 | 3 31 | 4 32 | 5 33 | 6 34 | 7 35 | 8 36 | 9 37 | 10 38 | 11 39 | 12 40 | 13 41 | 14 42 | 15 43 | 16 44 | 17 45 | 18 46 | 19 47 | 20 48 | 21 49 | 22 50 | 23 51 | 24 52 | 25 53 | 26 54 | 27 55 | 28 56 | 29 57 | 30 58 | 31 59 | 32 60 | 33 61 | 34 62 | 35 63 | 36 64 | 37 65 | 38 66 | 39 67 | 40 68 | 41 69 | 42 70 | 43 71 | 44 72 | 45 73 | 46 74 | 47 75 | 48 76 | 49 77 | 50 78 | 51 79 | 52 80 | 53 81 | 54 82 | 55 83 | 56 84 | 57 85 | 58 86 | 59 87 | 60 88 | 61 89 | 62 90 | 63 91 | 64 92 | 65 93 | 66 94 | 67 95 | 68 96 | 69 97 | 70 98 | 71 99 | 72 100 | 73 101 | 74 102 | 75 103 | 76 104 | 77 105 | 78 106 | 79 107 | 80 108 | 81 109 | 82 110 | 83 111 | 84 112 | 85 113 | 86 114 | 87 115 | 88 116 | 89 117 | 90 118 | 91 119 | 92 120 | 93 121 | 94 122 | 95 123 | 96 124 | 97 125 | 98 126 | 99 127 | 100 128 | 101 129 | 102 130 | 103 131 | 104 132 | 105 133 | 106 134 | 107 135 | 108 136 | 109 137 | 110 138 | 111 139 | 112 140 | 113 141 | 114 142 | 115 143 | 116 144 | 117 145 | 118 146 | 119 147 | 120 148 | 121 149 | 122 150 | 123 151 | 124 152 | 125 153 | 126 154 | 127 155 | 128 156 | 129  157 |   158 |   159 | 1 160 | 1 161 | 1 162 | 1 163 | 1 164 |   165 |   166 | 1 167 |   168 |   169 |   170 |   171 |   172 | 1 173 |   174 |   175 |   176 | 3 177 |   178 | 3 179 |   180 | 3 181 |   182 |   183 |   184 |   185 | 3 186 | 3 187 | 3 188 |   189 |   190 |   191 | 3 192 |   193 | 3 194 |   195 |   196 | 3 197 | 3 198 |   199 |   200 |   201 |   202 |   203 | 3 204 |   205 | 3 206 |   207 | 3 208 | 3 209 | 3 210 |   211 |   212 |   213 |   214 |   215 | 3 216 | 3 217 | 3 218 |   219 |   220 | 1 221 |   222 | 1 223 |   224 | 1 225 |   226 | 2 227 |   228 | 2 229 |   230 | 2 231 | 2 232 |   233 | 2 234 |   235 |   236 |   237 |   238 | 1 239 |   240 |   241 |   242 |   243 |   244 |   245 | 1 246 |   247 | 1 248 | 1 249 |   250 |   251 | 1 252 |   253 |   254 |   255 |   256 |   257 | 1 258 |   259 | 3 260 |   261 |   262 |   263 | 1 264 |   265 | 1 266 |   267 |   268 |   269 |   270 |   271 |   272 |   273 |   274 |   275 |   276 |   277 |   278 |   279 |   280 |   281 |   282 |   283 |   284 |  
'use strict';
285 |  
286 | //require all the things
287 | var _ = require( 'lodash' );
288 | var warn = require( './warn' );
289 | var appRoot = require( 'app-root-path' );
290 | var createServer = require( './init_server' );
291 | var u = require( 'common-utils' ).helpers;
292 |  
293 | //params for server options
294 | var params = [ 
295 | 				"Logging", 
296 | 				"Aws" 
297 | 			 ];
298 |  
299 | //order of information importance given fields, config.json, package.json, defaults
300 | function ServerObject( port, name, version, testing_flag ) { 
301 |  
302 | 	//For testing purposes
303 |  
304 | 	var serverRoot = appRoot;
305 | 	
306 | 	Eif( testing_flag ){
307 |  
308 | 		serverRoot = appRoot + "/test/lib/test_files";
309 | 	}
310 |  
311 | 	//Step 1: set the default values
312 | 	
313 | 	this.Port = 8080;
314 | 	this.Name = "Server";
315 | 	this.Version = "1.0.0";	
316 |  
317 | 	//Step 2: pull values from package.json, overrides defaults
318 |  
319 | 	var pkg = u.require_if_exists( serverRoot + "/package.json" );
320 |  
321 | 	Eif( pkg !== false ){
322 |  
323 | 		//this.Port = pkg.server.port || this.Port;
324 | 		this.Name = pkg.name || this.Name; 
325 | 		this.Version = pkg.version || this.Version;
326 |  
327 | 	}
328 |  
329 | 	//Step 3: pull values from config.json, overrides default and package.json
330 | 	
331 | 	var config = u.require_if_exists( serverRoot + "/config.json" );
332 |  
333 | 	Eif( config !== false ){
334 |  
335 | 		this.Port = config.server.port || this.Port;
336 | 		this.Name = config.server.name || this.Name; 
337 | 		this.Version = config.server.version || this.Version;
338 |  
339 | 	}
340 |  
341 | 	//Step 4: pull values from arguments, overrides everything else
342 | 	
343 | 	this.Port = port || this.Port;
344 | 	this.Name = name || this.Name; 
345 | 	this.Version = version || this.Version;
346 | }
347 |  
348 | function valueHandlers( object, params ) {
349 |  
350 | 	object.prototype.values = {};
351 |  
352 | 		params.forEach( function( param ){
353 |  
354 | 			object.prototype.values[ param ] = true;
355 |  
356 | 			object.prototype[ "with" + _.capitalize( param ) ] = function( val ){
357 | 			
358 | 			Iif( val ) {	this.values[ param ] = val; }
359 | 			else { this.values[ param] = true; }
360 |  
361 | 			return this;
362 | 		}
363 | 	});
364 | }
365 |  
366 | ServerObject.prototype.withConfig = function( configObject ) {
367 |  
368 | 	this.Port = configObject.server.port || 8080; 
369 | 	this.Name = configObject.server.name || "Server";
370 | 	this.Version = configObject.server.version || "1.0.0";
371 | }
372 |  
373 | ServerObject.prototype.routeOptions = function( options ){
374 |  
375 | 	this.routeOptions = options;
376 | 	return this;
377 | }
378 |  
379 | ServerObject.prototype.run = function() {
380 |  
381 | 	warn();	
382 | 	createServer( this );
383 | }
384 |  
385 | function create( port, name, version, author ) {
386 |  
387 | 	return new ServerObject( port, name, version, author );
388 | }
389 |  
390 | //add all the value handlers
391 | valueHandlers( ServerObject, params );
392 |  
393 | module.exports = {
394 |  
395 | 	create : create 
396 |  
397 | };
398 |  
399 |  
400 |  
401 |  
402 |  
403 |  
404 |  
405 |  
406 |  
407 |  
408 |  
409 |  
410 |  
411 |  
412 |  
414 | 415 |
416 | 419 | 420 | 427 | 428 | 429 | 430 | -------------------------------------------------------------------------------- /coverage/lcov-report/lib/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for lib/ 5 | 6 | 7 | 8 | 13 | 14 | 15 |
16 |

Code coverage report for lib/

17 |

18 | Statements: 58.43% (52 / 89)      19 | Branches: 33.33% (16 / 48)      20 | Functions: 37.5% (6 / 16)      21 | Lines: 60.47% (52 / 86)      22 | Ignored: none      23 |

24 |
All files » lib/
25 |
26 |
27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
FileStatementsBranchesFunctionsLines
builder.js87.5%(42 / 48)53.33%(16 / 30)75%(6 / 8)89.36%(42 / 47)
init_server.js15.63%(5 / 32)0%(0 / 14)0%(0 / 7)16.67%(5 / 30)
warn.js55.56%(5 / 9)0%(0 / 4)0%(0 / 1)55.56%(5 / 9)
84 |
85 |
86 | 89 | 90 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /coverage/lcov-report/lib/init_server.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for lib/init_server.js 5 | 6 | 7 | 8 | 13 | 14 | 15 |
16 |

Code coverage report for lib/init_server.js

17 |

18 | Statements: 15.63% (5 / 32)      19 | Branches: 0% (0 / 14)      20 | Functions: 0% (0 / 7)      21 | Lines: 16.67% (5 / 30)      22 | Ignored: none      23 |

24 |
All files » lib/ » init_server.js
25 |
26 |
27 |

 28 | 
299 | 
1 29 | 2 30 | 3 31 | 4 32 | 5 33 | 6 34 | 7 35 | 8 36 | 9 37 | 10 38 | 11 39 | 12 40 | 13 41 | 14 42 | 15 43 | 16 44 | 17 45 | 18 46 | 19 47 | 20 48 | 21 49 | 22 50 | 23 51 | 24 52 | 25 53 | 26 54 | 27 55 | 28 56 | 29 57 | 30 58 | 31 59 | 32 60 | 33 61 | 34 62 | 35 63 | 36 64 | 37 65 | 38 66 | 39 67 | 40 68 | 41 69 | 42 70 | 43 71 | 44 72 | 45 73 | 46 74 | 47 75 | 48 76 | 49 77 | 50 78 | 51 79 | 52 80 | 53 81 | 54 82 | 55 83 | 56 84 | 57 85 | 58 86 | 59 87 | 60 88 | 61 89 | 62 90 | 63 91 | 64 92 | 65 93 | 66 94 | 67 95 | 68 96 | 69 97 | 70 98 | 71 99 | 72 100 | 73 101 | 74 102 | 75 103 | 76 104 | 77 105 | 78 106 | 79 107 | 80 108 | 81 109 | 82 110 | 83 111 | 84 112 | 85 113 | 86 114 | 87 115 | 88 116 | 89 117 | 90 118 | 91  119 |   120 | 1 121 |   122 | 1 123 |   124 | 1 125 |   126 |   127 |   128 |   129 |   130 |   131 |   132 |   133 |   134 |   135 |   136 |   137 |   138 | 1 139 |   140 |   141 |   142 |   143 |   144 |   145 |   146 |   147 |   148 |   149 |   150 |   151 |   152 |   153 |   154 |   155 |   156 |   157 |   158 |   159 |   160 |   161 |   162 |   163 |   164 |   165 |   166 |   167 |   168 |   169 |   170 |   171 |   172 |   173 |   174 |   175 |   176 |   177 |   178 |   179 |   180 |   181 |   182 |   183 |   184 |   185 |   186 |   187 |   188 |   189 |   190 |   191 |   192 |   193 |   194 |   195 |   196 |   197 |   198 |   199 |   200 |   201 |   202 |   203 |   204 |   205 | 1 206 |   207 |   208 |  
'use strict';
209 |  
210 | var appRoot = require( 'app-root-path' ).path;
211 |  
212 | var fs = require( 'fs' );
213 |  
214 | function includeRoutes( routesPath, server ){
215 |  
216 | 	fs.readdirSync( routesPath ).forEach(function ( file ) {
217 |  
218 | 		if ( file.substr(-3, 3) === '.js' ) {
219 | 			
220 | 			require( routesPath + "/" + file.replace('.js', '')).addRoutes( server );
221 | 		}
222 | 		
223 | 	});
224 |  
225 | }
226 |  
227 | //only to be used as a module since routes directory does not exist
228 | function startServer( params ){
229 |  
230 | 	var options = params.values;
231 |  
232 | 	//import the logger
233 | 	var logger = require( './logger' );
234 |  
235 | 	//set up the debugging
236 | 	var debug = require( 'debug' )( 'main' );
237 |  
238 | 	//set up restify
239 | 	var restify = require( 'restify' );
240 | 	
241 | 	var routesPath = appRoot + "/routes";
242 |  
243 | 	if( options.logging ){
244 |  
245 | 		var server = restify.createServer( {
246 | 				name: params.name,
247 | 				log: logger,
248 | 				version: params.version
249 | 		});
250 |  
251 | 	} 
252 |  
253 | 	if( !options.logging ) {
254 |  
255 | 		var server = restify.createServer( {
256 | 				name: params.name,
257 | 				version: params.version
258 | 		});
259 | 	}
260 |  
261 | 	//basic restify configurations
262 | 	server.use( restify.queryParser() );
263 | 	server.use( restify.bodyParser({ mapParams: false }));
264 |  
265 | 	if( options.logging ){
266 |  
267 | 		server.pre( function (req, res, next) {  
268 | 		  
269 | 			//comment out this line to turn logging of in the console
270 | 			req.log.info({req: req}, 'START');
271 |  
272 | 			return next();
273 | 		});
274 | 	
275 | 	}
276 | 	
277 | 	// handle all uncaught errors - make sure they fit our error format
278 | 	server.on('uncaughtException', function( req, res, route, err) {
279 |  
280 | 		if( options.logging ) { logger.error( err, 'uncaught exception' ); }
281 |  
282 | 		res.send( 500, { code: 500, message: (err.toString() || 'error') } );
283 | 	});
284 |  
285 | 	includeRoutes( routesPath, server, params.routesOptions );
286 |  
287 | 	//Run server 
288 | 	server.listen( params.port, function() {
289 |  
290 | 		if( options.logging ) { logger.info( '%s listening at %s', server.name, server.url ) }
291 | 	});
292 |  
293 | }
294 |  
295 | module.exports = function( params ) {
296 |  
297 | 	startServer( params );
298 | }
300 | 301 |
302 | 305 | 306 | 313 | 314 | 315 | 316 | -------------------------------------------------------------------------------- /coverage/lcov-report/lib/warn.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for lib/warn.js 5 | 6 | 7 | 8 | 13 | 14 | 15 |
16 |

Code coverage report for lib/warn.js

17 |

18 | Statements: 55.56% (5 / 9)      19 | Branches: 0% (0 / 4)      20 | Functions: 0% (0 / 1)      21 | Lines: 55.56% (5 / 9)      22 | Ignored: none      23 |

24 |
All files » lib/ » warn.js
25 |
26 |
27 |

 28 | 
 92 | 
1 29 | 2 30 | 3 31 | 4 32 | 5 33 | 6 34 | 7 35 | 8 36 | 9 37 | 10 38 | 11 39 | 12 40 | 13 41 | 14 42 | 15 43 | 16 44 | 17 45 | 18 46 | 19 47 | 20 48 | 21 49 | 22  50 |   51 | 1 52 |   53 | 1 54 |   55 | 1 56 |   57 | 1 58 |   59 |   60 |   61 |   62 |   63 |   64 |   65 |   66 |   67 |   68 |   69 |   70 | 1
'use strict'
 71 |  
 72 | var jsonFile = require( 'jsonFile' );
 73 |  
 74 | var appRoot = require( 'app-root-path' ).path;
 75 |  
 76 | var pjson = require( appRoot + "/package.json" );
 77 |  
 78 | function warn( ){
 79 |  
 80 | 	if( pjson.name === "default" ){
 81 |  
 82 | 		console.warn( "@warning Edit the name of your server in package.json" );
 83 | 	}
 84 |  
 85 | 	if( pjson.author === "theMagicElf" ){
 86 | 		
 87 | 		console.warn( "@warning Edit the author of your server in package.json" );
 88 | 	}
 89 | }
 90 |  
 91 | module.exports = warn;
93 | 94 |
95 | 98 | 99 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /coverage/lcov-report/prettify.css: -------------------------------------------------------------------------------- 1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} 2 | -------------------------------------------------------------------------------- /coverage/lcov-report/prettify.js: -------------------------------------------------------------------------------- 1 | window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); 2 | -------------------------------------------------------------------------------- /coverage/lcov-report/sort-arrow-sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ttaub/simple-restify/9de054300484ba4af50386bfcec8ae06175f3c92/coverage/lcov-report/sort-arrow-sprite.png -------------------------------------------------------------------------------- /coverage/lcov-report/sorter.js: -------------------------------------------------------------------------------- 1 | var addSorting = (function () { 2 | "use strict"; 3 | var cols, 4 | currentSort = { 5 | index: 0, 6 | desc: false 7 | }; 8 | 9 | // returns the summary table element 10 | function getTable() { return document.querySelector('.coverage-summary table'); } 11 | // returns the thead element of the summary table 12 | function getTableHeader() { return getTable().querySelector('thead tr'); } 13 | // returns the tbody element of the summary table 14 | function getTableBody() { return getTable().querySelector('tbody'); } 15 | // returns the th element for nth column 16 | function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; } 17 | 18 | // loads all columns 19 | function loadColumns() { 20 | var colNodes = getTableHeader().querySelectorAll('th'), 21 | colNode, 22 | cols = [], 23 | col, 24 | i; 25 | 26 | for (i = 0; i < colNodes.length; i += 1) { 27 | colNode = colNodes[i]; 28 | col = { 29 | key: colNode.getAttribute('data-col'), 30 | sortable: !colNode.getAttribute('data-nosort'), 31 | type: colNode.getAttribute('data-type') || 'string' 32 | }; 33 | cols.push(col); 34 | if (col.sortable) { 35 | col.defaultDescSort = col.type === 'number'; 36 | colNode.innerHTML = colNode.innerHTML + ''; 37 | } 38 | } 39 | return cols; 40 | } 41 | // attaches a data attribute to every tr element with an object 42 | // of data values keyed by column name 43 | function loadRowData(tableRow) { 44 | var tableCols = tableRow.querySelectorAll('td'), 45 | colNode, 46 | col, 47 | data = {}, 48 | i, 49 | val; 50 | for (i = 0; i < tableCols.length; i += 1) { 51 | colNode = tableCols[i]; 52 | col = cols[i]; 53 | val = colNode.getAttribute('data-value'); 54 | if (col.type === 'number') { 55 | val = Number(val); 56 | } 57 | data[col.key] = val; 58 | } 59 | return data; 60 | } 61 | // loads all row data 62 | function loadData() { 63 | var rows = getTableBody().querySelectorAll('tr'), 64 | i; 65 | 66 | for (i = 0; i < rows.length; i += 1) { 67 | rows[i].data = loadRowData(rows[i]); 68 | } 69 | } 70 | // sorts the table using the data for the ith column 71 | function sortByIndex(index, desc) { 72 | var key = cols[index].key, 73 | sorter = function (a, b) { 74 | a = a.data[key]; 75 | b = b.data[key]; 76 | return a < b ? -1 : a > b ? 1 : 0; 77 | }, 78 | finalSorter = sorter, 79 | tableBody = document.querySelector('.coverage-summary tbody'), 80 | rowNodes = tableBody.querySelectorAll('tr'), 81 | rows = [], 82 | i; 83 | 84 | if (desc) { 85 | finalSorter = function (a, b) { 86 | return -1 * sorter(a, b); 87 | }; 88 | } 89 | 90 | for (i = 0; i < rowNodes.length; i += 1) { 91 | rows.push(rowNodes[i]); 92 | tableBody.removeChild(rowNodes[i]); 93 | } 94 | 95 | rows.sort(finalSorter); 96 | 97 | for (i = 0; i < rows.length; i += 1) { 98 | tableBody.appendChild(rows[i]); 99 | } 100 | } 101 | // removes sort indicators for current column being sorted 102 | function removeSortIndicators() { 103 | var col = getNthColumn(currentSort.index), 104 | cls = col.className; 105 | 106 | cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); 107 | col.className = cls; 108 | } 109 | // adds sort indicators for current column being sorted 110 | function addSortIndicators() { 111 | getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted'; 112 | } 113 | // adds event listeners for all sorter widgets 114 | function enableUI() { 115 | var i, 116 | el, 117 | ithSorter = function ithSorter(i) { 118 | var col = cols[i]; 119 | 120 | return function () { 121 | var desc = col.defaultDescSort; 122 | 123 | if (currentSort.index === i) { 124 | desc = !currentSort.desc; 125 | } 126 | sortByIndex(i, desc); 127 | removeSortIndicators(); 128 | currentSort.index = i; 129 | currentSort.desc = desc; 130 | addSortIndicators(); 131 | }; 132 | }; 133 | for (i =0 ; i < cols.length; i += 1) { 134 | if (cols[i].sortable) { 135 | el = getNthColumn(i).querySelector('.sorter'); 136 | if (el.addEventListener) { 137 | el.addEventListener('click', ithSorter(i)); 138 | } else { 139 | el.attachEvent('onclick', ithSorter(i)); 140 | } 141 | } 142 | } 143 | } 144 | // adds sorting functionality to the UI 145 | return function () { 146 | if (!getTable()) { 147 | return; 148 | } 149 | cols = loadColumns(); 150 | loadData(cols); 151 | addSortIndicators(); 152 | enableUI(); 153 | }; 154 | })(); 155 | 156 | window.addEventListener('load', addSorting); 157 | -------------------------------------------------------------------------------- /coverage/lcov.info: -------------------------------------------------------------------------------- 1 | TN: 2 | SF:/Users/tomt/Projects/jeeko/common-server/lib/builder.js 3 | FN:17,ServerObject 4 | FN:65,valueHandlers 5 | FN:69,(anonymous_3) 6 | FN:73,(anonymous_4) 7 | FN:83,(anonymous_5) 8 | FN:90,(anonymous_6) 9 | FN:96,(anonymous_7) 10 | FN:102,create 11 | FNF:8 12 | FNH:6 13 | FNDA:3,ServerObject 14 | FNDA:1,valueHandlers 15 | FNDA:2,(anonymous_3) 16 | FNDA:2,(anonymous_4) 17 | FNDA:0,(anonymous_5) 18 | FNDA:1,(anonymous_6) 19 | FNDA:0,(anonymous_7) 20 | FNDA:3,create 21 | DA:4,1 22 | DA:5,1 23 | DA:6,1 24 | DA:7,1 25 | DA:8,1 26 | DA:11,1 27 | DA:17,1 28 | DA:21,3 29 | DA:23,3 30 | DA:25,3 31 | DA:30,3 32 | DA:31,3 33 | DA:32,3 34 | DA:36,3 35 | DA:38,3 36 | DA:41,3 37 | DA:42,3 38 | DA:48,3 39 | DA:50,3 40 | DA:52,3 41 | DA:53,3 42 | DA:54,3 43 | DA:60,3 44 | DA:61,3 45 | DA:62,3 46 | DA:65,1 47 | DA:67,1 48 | DA:69,1 49 | DA:71,2 50 | DA:73,2 51 | DA:75,2 52 | DA:76,2 53 | DA:78,2 54 | DA:83,1 55 | DA:85,0 56 | DA:86,0 57 | DA:87,0 58 | DA:90,1 59 | DA:92,1 60 | DA:93,1 61 | DA:96,1 62 | DA:98,0 63 | DA:99,0 64 | DA:102,1 65 | DA:104,3 66 | DA:108,1 67 | DA:110,1 68 | LF:47 69 | LH:42 70 | BRDA:23,1,0,3 71 | BRDA:23,1,1,0 72 | BRDA:38,2,0,3 73 | BRDA:38,2,1,0 74 | BRDA:41,3,0,3 75 | BRDA:41,3,1,0 76 | BRDA:42,4,0,3 77 | BRDA:42,4,1,0 78 | BRDA:50,5,0,3 79 | BRDA:50,5,1,0 80 | BRDA:52,6,0,3 81 | BRDA:52,6,1,0 82 | BRDA:53,7,0,3 83 | BRDA:53,7,1,3 84 | BRDA:54,8,0,3 85 | BRDA:54,8,1,0 86 | BRDA:60,9,0,3 87 | BRDA:60,9,1,2 88 | BRDA:61,10,0,3 89 | BRDA:61,10,1,3 90 | BRDA:62,11,0,3 91 | BRDA:62,11,1,3 92 | BRDA:75,12,0,0 93 | BRDA:75,12,1,2 94 | BRDA:85,13,0,0 95 | BRDA:85,13,1,0 96 | BRDA:86,14,0,0 97 | BRDA:86,14,1,0 98 | BRDA:87,15,0,0 99 | BRDA:87,15,1,0 100 | BRF:30 101 | BRH:16 102 | end_of_record 103 | TN: 104 | SF:/Users/tomt/Projects/jeeko/common-server/lib/warn.js 105 | FN:9,warn 106 | FNF:1 107 | FNH:0 108 | FNDA:0,warn 109 | DA:3,1 110 | DA:5,1 111 | DA:7,1 112 | DA:9,1 113 | DA:11,0 114 | DA:13,0 115 | DA:16,0 116 | DA:18,0 117 | DA:22,1 118 | LF:9 119 | LH:5 120 | BRDA:11,1,0,0 121 | BRDA:11,1,1,0 122 | BRDA:16,2,0,0 123 | BRDA:16,2,1,0 124 | BRF:4 125 | BRH:0 126 | end_of_record 127 | TN: 128 | SF:/Users/tomt/Projects/jeeko/common-server/lib/init_server.js 129 | FN:7,includeRoutes 130 | FN:9,(anonymous_2) 131 | FN:21,startServer 132 | FN:60,(anonymous_4) 133 | FN:71,(anonymous_5) 134 | FN:81,(anonymous_6) 135 | FN:88,(anonymous_7) 136 | FNF:7 137 | FNH:0 138 | FNDA:0,includeRoutes 139 | FNDA:0,(anonymous_2) 140 | FNDA:0,startServer 141 | FNDA:0,(anonymous_4) 142 | FNDA:0,(anonymous_5) 143 | FNDA:0,(anonymous_6) 144 | FNDA:0,(anonymous_7) 145 | DA:3,1 146 | DA:5,1 147 | DA:7,1 148 | DA:9,0 149 | DA:11,0 150 | DA:13,0 151 | DA:21,1 152 | DA:23,0 153 | DA:26,0 154 | DA:29,0 155 | DA:32,0 156 | DA:34,0 157 | DA:36,0 158 | DA:38,0 159 | DA:46,0 160 | DA:48,0 161 | DA:55,0 162 | DA:56,0 163 | DA:58,0 164 | DA:60,0 165 | DA:63,0 166 | DA:65,0 167 | DA:71,0 168 | DA:73,0 169 | DA:75,0 170 | DA:78,0 171 | DA:81,0 172 | DA:83,0 173 | DA:88,1 174 | DA:90,0 175 | LF:30 176 | LH:5 177 | BRDA:11,1,0,0 178 | BRDA:11,1,1,0 179 | BRDA:36,2,0,0 180 | BRDA:36,2,1,0 181 | BRDA:46,3,0,0 182 | BRDA:46,3,1,0 183 | BRDA:58,4,0,0 184 | BRDA:58,4,1,0 185 | BRDA:73,5,0,0 186 | BRDA:73,5,1,0 187 | BRDA:75,6,0,0 188 | BRDA:75,6,1,0 189 | BRDA:83,7,0,0 190 | BRDA:83,7,1,0 191 | BRF:14 192 | BRH:0 193 | end_of_record 194 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require( './lib/builder' ); 4 | -------------------------------------------------------------------------------- /lib/builder.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | //require the dependencies 4 | var _ = require( 'lodash' ); 5 | var appRoot = require( 'app-root-path' ).path; 6 | var u = require( 'common-utils' ).helpers; 7 | var restify = require( 'restify' ); 8 | var fs = require( 'fs' ); 9 | var Promise = require( 'bluebird' ); 10 | 11 | 12 | ///////////////// HELPER METHODS /////////////// 13 | 14 | function createServer( info ){ 15 | 16 | var logger = require( './logger' ); 17 | 18 | var server = restify.createServer( { 19 | name: info.name, 20 | log: logger, 21 | version: info.version 22 | }); 23 | 24 | return server; 25 | } 26 | 27 | function includeRoutes( routesPath, server, options ){ 28 | 29 | fs.readdirSync( routesPath ).forEach(function ( file ) { 30 | 31 | if ( file.substr( -3, 3 ) === '.js' ) { 32 | 33 | require( routesPath + "/" + file.replace('.js', '')).init( server, options ); 34 | } 35 | 36 | }); 37 | } 38 | 39 | //////////////////////////////////////////////// 40 | 41 | //Import configObject into the creation or use the default values 42 | function ServerObject( configObject ) { 43 | 44 | this.info = { 45 | 46 | port : 8000, 47 | name : "Restify Server", 48 | version : "1.0.0", 49 | rootPath : appRoot, 50 | routesPath : appRoot + "/routes", 51 | routesOptions : {}, 52 | logging : true 53 | } 54 | 55 | _.assign( this.info, configObject ); 56 | 57 | //create the server 58 | this.server = createServer( this.info ); 59 | } 60 | 61 | //configure the server, only called by this class 62 | ServerObject.prototype._configServer = function(){ 63 | 64 | this.server.use( restify.queryParser() ); 65 | this.server.use( restify.bodyParser({ mapParams: false })); 66 | 67 | if( this.info.logging ) { 68 | 69 | this.server.pre( function (req, res, next) { 70 | req.log.info({req: req}, 'START'); 71 | return next(); 72 | }); 73 | 74 | } 75 | 76 | includeRoutes( this.info.routesPath, this.server, this.info.routesOptions ); 77 | } 78 | 79 | //specify the routeOptions 80 | ServerObject.prototype.routesOptions = function( options ){ 81 | 82 | this.info.routesOptions = options; 83 | return this; 84 | 85 | } 86 | 87 | //add functionality to the server 88 | ServerObject.prototype.add = function( cb ){ 89 | 90 | this.server = cb( this.server ); 91 | return this; 92 | } 93 | 94 | //run the server 95 | ServerObject.prototype.run = function( cb ) { 96 | 97 | //configure the server 98 | this._configServer(); 99 | 100 | var server = this.server; 101 | 102 | var info = this.info; 103 | 104 | server.listen( info.port, function(){ 105 | 106 | console.log( '%s listening at %s', server.name, server.url ); 107 | 108 | }); 109 | 110 | return server; 111 | } 112 | 113 | //create the object 114 | function config( configObject ) { 115 | 116 | return new ServerObject( configObject); 117 | } 118 | 119 | module.exports = { config : config } 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /lib/logger.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Logging module. 3 | * 4 | * @module lib/logger 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var bunyan = require( 'bunyan' ); 10 | 11 | var restify = require( 'restify' ); 12 | 13 | var commonLogging = require( 'common-logging' ); 14 | 15 | var logger = bunyan.createLogger({ 16 | name: 'jeeko', 17 | streams: [ 18 | { 19 | level: 'debug', 20 | stream: process.stdout // log INFO and above to stdout 21 | } 22 | // ,{ 23 | // level: 'error', 24 | // path: '/var/tmp/jeeko.log' // log ERROR and above to a file 25 | // } 26 | ], 27 | serializers: commonLogging.updateSerializers( restify.bunyan.serializers ) 28 | }); 29 | 30 | module.exports = logger; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "common-server", 3 | "version": "1.0.0", 4 | "description": "Hassle free server configurations", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "jshint server.js lib/**.js", 8 | "test": "./node_modules/.bin/istanbul test ./node_modules/.bin/_mocha -- --recursive test/", 9 | "test-ci": "./node_modules/.bin/istanbul test ./node_modules/.bin/_mocha -- --recursive integration/" 10 | }, 11 | "author": "ttaubkin", 12 | "dependencies": { 13 | "app-root-path": "^1.0.0", 14 | "assert-plus": "^0.1.5", 15 | "bluebird": "^2.9.24", 16 | "bunyan": "^1.3.3", 17 | "debug": "^2.2.0", 18 | "jsonfile": "^2.2.1", 19 | "lodash": "^3.10.1", 20 | "moment": "^2.8.4", 21 | "node-uuid": "^1.4.2", 22 | "request": "^2.60.0", 23 | "restify": "^3.0.2", 24 | "superagent": "^1.3.0" 25 | }, 26 | "devDependencies": { 27 | "chai": "^1.10.0", 28 | "chance": "^0.7.4", 29 | "istanbul": "^0.3.5", 30 | "jshint": "^2.5.11", 31 | "mocha": "^2.1.0", 32 | "node-fetch": "^1.2.1", 33 | "sinon": "^1.12.2" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /simple-restify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ttaub/simple-restify/9de054300484ba4af50386bfcec8ae06175f3c92/simple-restify.png -------------------------------------------------------------------------------- /test/builder.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | //require 4 | var expect = require( 'chai' ).expect; 5 | var Builder = require( '../lib/builder' ); 6 | var path = require( 'app-root-path' ).path; 7 | 8 | 9 | 10 | describe( 'builder.js', function() { 11 | 12 | describe( 'create object', function(){ 13 | 14 | it( 'normal operation', function() { 15 | 16 | var info = Builder 17 | .config() 18 | .info; 19 | var res = { 20 | 21 | 'port' : 8000, 22 | 'name' : 'Restify Server', 23 | 'version' : '1.0.0', 24 | 'rootPath' : path, 25 | 'routesPath' : path + '/routes', 26 | 'routesOptions' : {}, 27 | 'logging' : true 28 | }; 29 | 30 | expect( info ).to.eql( res ); 31 | 32 | }); 33 | 34 | it( 'with params', function() { 35 | 36 | var data = { 37 | 38 | 'port' : 3000, 39 | 'name' : 'moses', 40 | 'version' : '2.0.0', 41 | 'logging' : false 42 | }; 43 | 44 | var info = Builder 45 | .config( data ) 46 | .info; 47 | 48 | var res = { 49 | 50 | 'port' : 3000, 51 | 'name' : 'moses', 52 | 'version' : '2.0.0', 53 | 'rootPath' : path, 54 | 'routesPath' : path + '/routes', 55 | 'routesOptions' : {}, 56 | 'logging' : false 57 | }; 58 | 59 | expect( info ).to.eql( res ); 60 | 61 | }); 62 | 63 | it( 'addRoutes for object', function() { 64 | 65 | var data = { 66 | 67 | 'port' : 3000, 68 | 'name' : 'moses', 69 | 'version' : '2.0.0', 70 | 'logging' : false 71 | }; 72 | 73 | var info = Builder 74 | .config( data ) 75 | .routesOptions( { 'test' : 'test' } ) 76 | .info; 77 | 78 | var res = { 79 | 80 | 'port' : 3000, 81 | 'name' : 'moses', 82 | 'version' : '2.0.0', 83 | 'rootPath' : path, 84 | 'routesPath' : path + '/routes', 85 | 'routesOptions' : { 'test' : 'test' }, 86 | 'logging' : false 87 | }; 88 | 89 | expect( info ).to.eql( res ); 90 | 91 | }); 92 | 93 | }); 94 | 95 | }); 96 | -------------------------------------------------------------------------------- /test/integration/routes/health.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | function health( req, res, next ) { 4 | 5 | res.send( 'Ok!' ); 6 | 7 | next( false ); 8 | } 9 | 10 | function init( server ) { 11 | 12 | server.get( '/health', health ); 13 | } 14 | 15 | module.exports = { 16 | 17 | init : init 18 | }; -------------------------------------------------------------------------------- /test/integration/routes/withParams.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var options = {}; 4 | 5 | //say hello with params 6 | function sayHello( req, res, next ) { 7 | 8 | res.send( 'Hey! ' + options.name ); 9 | } 10 | 11 | //initalize the functions 12 | function init( server, routeOptions ) { 13 | 14 | options = routeOptions; 15 | 16 | server.get( '/withParams', sayHello ); 17 | } 18 | 19 | module.exports = { 20 | 21 | init: init 22 | } 23 | 24 | -------------------------------------------------------------------------------- /test/integration/server.test.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | //requires 4 | var expect = require( 'chai' ).expect; 5 | var Builder = require( '../../lib/builder.js' ); 6 | var superagent = require( 'superagent' ); 7 | 8 | describe( 'Builder module', function( ) { 9 | 10 | var routes = __dirname + '/routes'; 11 | 12 | describe( 'server creation', function(){ 13 | 14 | it('create a simple server', function(){ 15 | 16 | var server = Builder 17 | .config({ 'routesPath' : routes, 'port' : 3000 } ) 18 | .run(); 19 | 20 | superagent 21 | .get( 'http://localhost:3000/health' ) 22 | .end( function( err, res ){ 23 | 24 | expect( res.body ).to.equal( 'Ok!' ); 25 | server.close(); 26 | 27 | }); 28 | }); 29 | 30 | it('custom config', function(){ 31 | 32 | var server = Builder 33 | .config({ 'routesPath' : routes, 'port' : 3000, 'logging' : false } ) 34 | .run(); 35 | 36 | superagent 37 | .get( 'http://localhost:3000/health' ) 38 | .end( function( err, res ){ 39 | 40 | expect( res.body ).to.equal( 'Ok!' ); 41 | server.close(); 42 | 43 | }); 44 | }); 45 | }); 46 | 47 | describe( 'server options', function(){ 48 | 49 | it( '.add()', function(){ 50 | 51 | var server = Builder 52 | .config( { 'routesPath' : routes, 'port' : 3000, 'logging' : false } ) 53 | .add( function( server ){ 54 | 55 | server.get( '/test', function( req, res, next ) { 56 | 57 | res.send( 'Moses!' ); 58 | }); 59 | 60 | return server; 61 | }) 62 | .run(); 63 | 64 | superagent 65 | .get( 'http://localhost:3000/test' ) 66 | .end( function( err, res ){ 67 | 68 | expect( res.body ).to.equal( 'Moses!' ); 69 | server.close(); 70 | 71 | }); 72 | 73 | }); 74 | 75 | it( '.routesOptions()', function(){ 76 | 77 | var server = Builder 78 | .config( { 'routesPath' : routes, 'port' : 3000, 'logging' : false } ) 79 | .routesOptions( { 'name' : 'moses' } ) 80 | .run(); 81 | 82 | superagent 83 | .get( 'http://localhost:3000/withParams' ) 84 | .end( function( err, res ) { 85 | 86 | //console.log( res.body ); 87 | 88 | expect( res ).to.eql( 'Hey! moses' ); 89 | server.close(); 90 | }); 91 | }); 92 | 93 | }); 94 | 95 | }); --------------------------------------------------------------------------------