├── .env.sample ├── .gitignore ├── CONTRIBUTING.md ├── Cargo.lock ├── Cargo.toml ├── README.md ├── src ├── config.rs ├── endpoints │ ├── index.rs │ └── mod.rs ├── logger │ ├── logger.rs │ └── mod.rs ├── main.rs └── routes.rs └── start.sh /.env.sample: -------------------------------------------------------------------------------- 1 | # Define your Rust version for your project 2 | # The version below was used to build this project and is stable to it 3 | # but go ahead and try it out to put another version. 4 | # 5 | # This environment variable is used to run a Rust script that checks the 6 | # present Rust version and make sure it's being developed at the proper version 7 | RUSTC_VERSION=1.34.1 8 | 9 | # Define verbosity for app logs as below: 10 | # 0 for showing only warns and errors; 11 | # 1 for showing info, warns and errors; 12 | # 2 or more for debug, info, warns and errors. 13 | # 14 | # Note: this value is received as String and parsed to u8. So don't expect great success in life sending 256 ;) 15 | LEVEL_VERBOSITY=1 16 | 17 | # Definition for your server port 18 | SERVER_PORT=4545 19 | 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .env 3 | output.log 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Quanto Dev Portal Contributing 2 | 3 | ## Git Rules 4 | 5 | ### Main branches 6 | 7 | - `develop` 8 | 9 | origin: `staging` 10 | 11 | what: Releases in development. Only mergeable via Pull Request 12 | 13 | - `staging`: 14 | 15 | origin: `master` 16 | 17 | what: This branch receives patches from `develop` branch as release candidates and is supposed to be stable code, with proper version number, to final tests on an mirror to production environment; 18 | 19 | - `master`: 20 | 21 | what: This branch runs stable code and is directly related to production. Every push in this branch sends this code version to production; 22 | 23 | ### Branches names 24 | 25 | `$branchType/$branch-description` 26 | 27 | #### Language 28 | 29 | Branches we write in English. It's just convention. 30 | 31 | #### $branchType 32 | 33 | - `fix`: fixes a bug; 34 | - `feat`: adds a new feature; 35 | - `refactor`: refactors/improves an existing feature; 36 | - `chore`: config changes, tools/libraries updates, builds adjustments and so forth; 37 | - `docs`: documentation updates, no production code updated. 38 | 39 | #### $branch-description 40 | 41 | A short trace separated message describing what is being developed. 42 | 43 | #### Good examples of branches names 44 | 45 | - `feat/user-preferences` 46 | - `refactor/product-creation` 47 | - `fix/organization-update` 48 | - `chore/remote-signer-secrets` 49 | 50 | #### Bad examples of branches names 51 | 52 | - `feat/user-preferences-fields-with-validations`: too long, specifications should be in commits 53 | - `refactor/product`: too short and doesn't say anything about what is being refactored 54 | - `fix/add-new-user`: it's ambiguous, we should take care to do not looks like the type is not related to its action 55 | - `feat-user-preferences`: out of convention, the `feat` type and `user-preferences` description should be separated with slash `/`. 56 | 57 | ### Commit messages 58 | 59 | $action($scope): $commitTitle 60 | 61 | $commitBody 62 | 63 | #### Language 64 | 65 | Commits we write in English. It's just convention. 66 | 67 | #### $action 68 | 69 | Action type made in the commit in context: 70 | 71 | - `fix`: bugs fixes; 72 | - `hotfix`: critical bug fixes passive to be sent to main branches (see Main Branches section) without a Pull Request; 73 | - `refactor`: refactoring or improving existing features; 74 | - `chore`: Config changes, tools/libraries updates, builds adjustments and so forth; 75 | - `test`: Add missing tests or refactoring tests; no production code change; 76 | - `docs`: changes or increments to the documentation; 77 | - `style`: formatting, missing semi colons, etc; no production code changed; 78 | - `feat`: when it adds a new feature or belongs specifically to a feature development and it's not related to any fix, hotfix, refactor or chore in the application. 79 | 80 | #### $scope 81 | 82 | The scope you're working on. Good examples of scope are: 83 | 84 | - user 85 | - database 86 | - config 87 | - proxy 88 | - server-init 89 | 90 | #### $commitTitle 91 | 92 | The first line cannot be longer than 70 characters, the second line is always blank and other lines should be wrapped at 80 characters. The type and scope should always be lowercase as shown below. 93 | 94 | #### $commitBody 95 | 96 | - uses the imperative, present tense: "change" not "changed" nor "changes" 97 | - includes motivation for the change and contrasts with previous behavior 98 | 99 | ### Creating a Pull Request 100 | 101 | #### Language 102 | 103 | Pull Requests we write in Portuguese, since it's our primary language and it makes easier to everyone understand what's being released. 104 | 105 | #### Pull Request Title 106 | 107 | First thing in a Pull Request title is its prefix. 108 | 109 | `[$ACTION] $message` 110 | 111 | ##### $ACTION 112 | 113 | The possible actions are: 114 | 115 | - `FIX` 116 | - `HOTFIX` 117 | - `FEAT` 118 | - `REFACTOR` 119 | - `DOCS` 120 | - `CHORE` 121 | 122 | ##### $message 123 | 124 | A simple message of this Pull Request as its title. It must be concise and short. 125 | 126 | ##### Example 127 | 128 | [FIX] Organization Resources loading 129 | 130 | #### Pull Request body 131 | 132 | It's the release note of this Pull Request. It must be detailed but not lengthened. If you can make it short then do it. Just think it's a message that everyone must understand, from programmers to non-programmers. 133 | 134 | The last line of the Pull Request body you place a footer information for relating to the issues it's related and can be closed, like: 135 | 136 | ``` 137 | Closes #234 138 | ``` 139 | 140 | In case of multiple issues: 141 | 142 | ``` 143 | Closes #453, #567 144 | ``` 145 | 146 | ### Git flow in a row 147 | 148 | Create your branch → Build and commit → open a Pull Request to `develop` branch → deliver 149 | 150 | ## References (or copy/paste) 151 | 152 | [https://karma-runner.github.io/1.0/dev/git-commit-msg.html](https://karma-runner.github.io/1.0/dev/git-commit-msg.html) 153 | 154 | [https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716](https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716) 155 | 156 | [https://www.conventionalcommits.org/en/v1.0.0-beta.3/](https://www.conventionalcommits.org/en/v1.0.0-beta.3/) 157 | 158 | [https://medium.com/@roalcantara/a-guide-to-improve-the-git-hub-flow-and-commits-messages-b495461e1115](https://medium.com/@roalcantara/a-guide-to-improve-the-git-hub-flow-and-commits-messages-b495461e1115) 159 | 160 | [https://www.atlassian.com/git/tutorials/merging-vs-rebasing](https://www.atlassian.com/git/tutorials/merging-vs-rebasing) 161 | 162 | [https://www.atlassian.com/git/articles/git-team-workflows-merge-or-rebase](https://www.atlassian.com/git/articles/git-team-workflows-merge-or-rebase) 163 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "autocfg" 5 | version = "0.1.2" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | 8 | [[package]] 9 | name = "base64" 10 | version = "0.9.3" 11 | source = "registry+https://github.com/rust-lang/crates.io-index" 12 | dependencies = [ 13 | "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 14 | "safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 15 | ] 16 | 17 | [[package]] 18 | name = "bitflags" 19 | version = "1.0.4" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | 22 | [[package]] 23 | name = "byteorder" 24 | version = "1.3.1" 25 | source = "registry+https://github.com/rust-lang/crates.io-index" 26 | 27 | [[package]] 28 | name = "cfg-if" 29 | version = "0.1.7" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | 32 | [[package]] 33 | name = "chrono" 34 | version = "0.4.6" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | dependencies = [ 37 | "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 38 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 39 | "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", 40 | ] 41 | 42 | [[package]] 43 | name = "cloudabi" 44 | version = "0.0.3" 45 | source = "registry+https://github.com/rust-lang/crates.io-index" 46 | dependencies = [ 47 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 48 | ] 49 | 50 | [[package]] 51 | name = "colored" 52 | version = "1.7.0" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | dependencies = [ 55 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 56 | ] 57 | 58 | [[package]] 59 | name = "fern" 60 | version = "0.5.8" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | dependencies = [ 63 | "colored 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 64 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 65 | ] 66 | 67 | [[package]] 68 | name = "fuchsia-cprng" 69 | version = "0.1.1" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | 72 | [[package]] 73 | name = "httparse" 74 | version = "1.3.3" 75 | source = "registry+https://github.com/rust-lang/crates.io-index" 76 | 77 | [[package]] 78 | name = "hyper" 79 | version = "0.10.15" 80 | source = "registry+https://github.com/rust-lang/crates.io-index" 81 | dependencies = [ 82 | "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", 83 | "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 84 | "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 85 | "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 86 | "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 87 | "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 88 | "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", 89 | "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 90 | "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 91 | "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 92 | "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", 93 | ] 94 | 95 | [[package]] 96 | name = "idna" 97 | version = "0.1.5" 98 | source = "registry+https://github.com/rust-lang/crates.io-index" 99 | dependencies = [ 100 | "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 101 | "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 102 | "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 103 | ] 104 | 105 | [[package]] 106 | name = "iron" 107 | version = "0.6.0" 108 | source = "registry+https://github.com/rust-lang/crates.io-index" 109 | dependencies = [ 110 | "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", 111 | "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 112 | "mime_guess 1.8.6 (registry+https://github.com/rust-lang/crates.io-index)", 113 | "modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 114 | "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 115 | "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 116 | "typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 117 | "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", 118 | ] 119 | 120 | [[package]] 121 | name = "language-tags" 122 | version = "0.2.2" 123 | source = "registry+https://github.com/rust-lang/crates.io-index" 124 | 125 | [[package]] 126 | name = "lazy_static" 127 | version = "1.3.0" 128 | source = "registry+https://github.com/rust-lang/crates.io-index" 129 | 130 | [[package]] 131 | name = "libc" 132 | version = "0.2.51" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | 135 | [[package]] 136 | name = "log" 137 | version = "0.3.9" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | dependencies = [ 140 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 141 | ] 142 | 143 | [[package]] 144 | name = "log" 145 | version = "0.4.6" 146 | source = "registry+https://github.com/rust-lang/crates.io-index" 147 | dependencies = [ 148 | "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 149 | ] 150 | 151 | [[package]] 152 | name = "matches" 153 | version = "0.1.8" 154 | source = "registry+https://github.com/rust-lang/crates.io-index" 155 | 156 | [[package]] 157 | name = "mime" 158 | version = "0.2.6" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | dependencies = [ 161 | "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 162 | ] 163 | 164 | [[package]] 165 | name = "mime_guess" 166 | version = "1.8.6" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | dependencies = [ 169 | "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 170 | "phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)", 171 | "phf_codegen 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)", 172 | "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 173 | ] 174 | 175 | [[package]] 176 | name = "modifier" 177 | version = "0.1.0" 178 | source = "registry+https://github.com/rust-lang/crates.io-index" 179 | 180 | [[package]] 181 | name = "mtmr0x_web_boilerplate" 182 | version = "0.0.1" 183 | dependencies = [ 184 | "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 185 | "fern 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", 186 | "iron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 187 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 188 | "router 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 189 | "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 190 | ] 191 | 192 | [[package]] 193 | name = "num-integer" 194 | version = "0.1.39" 195 | source = "registry+https://github.com/rust-lang/crates.io-index" 196 | dependencies = [ 197 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 198 | ] 199 | 200 | [[package]] 201 | name = "num-traits" 202 | version = "0.2.6" 203 | source = "registry+https://github.com/rust-lang/crates.io-index" 204 | 205 | [[package]] 206 | name = "num_cpus" 207 | version = "1.10.0" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | dependencies = [ 210 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 211 | ] 212 | 213 | [[package]] 214 | name = "percent-encoding" 215 | version = "1.0.1" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | 218 | [[package]] 219 | name = "phf" 220 | version = "0.7.24" 221 | source = "registry+https://github.com/rust-lang/crates.io-index" 222 | dependencies = [ 223 | "phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)", 224 | ] 225 | 226 | [[package]] 227 | name = "phf_codegen" 228 | version = "0.7.24" 229 | source = "registry+https://github.com/rust-lang/crates.io-index" 230 | dependencies = [ 231 | "phf_generator 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)", 232 | "phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)", 233 | ] 234 | 235 | [[package]] 236 | name = "phf_generator" 237 | version = "0.7.24" 238 | source = "registry+https://github.com/rust-lang/crates.io-index" 239 | dependencies = [ 240 | "phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)", 241 | "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", 242 | ] 243 | 244 | [[package]] 245 | name = "phf_shared" 246 | version = "0.7.24" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | dependencies = [ 249 | "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 250 | "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 251 | ] 252 | 253 | [[package]] 254 | name = "plugin" 255 | version = "0.2.6" 256 | source = "registry+https://github.com/rust-lang/crates.io-index" 257 | dependencies = [ 258 | "typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 259 | ] 260 | 261 | [[package]] 262 | name = "rand" 263 | version = "0.6.5" 264 | source = "registry+https://github.com/rust-lang/crates.io-index" 265 | dependencies = [ 266 | "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 267 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 268 | "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 269 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 270 | "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 271 | "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 272 | "rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 273 | "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 274 | "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 275 | "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 276 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 277 | ] 278 | 279 | [[package]] 280 | name = "rand_chacha" 281 | version = "0.1.1" 282 | source = "registry+https://github.com/rust-lang/crates.io-index" 283 | dependencies = [ 284 | "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 285 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 286 | ] 287 | 288 | [[package]] 289 | name = "rand_core" 290 | version = "0.3.1" 291 | source = "registry+https://github.com/rust-lang/crates.io-index" 292 | dependencies = [ 293 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 294 | ] 295 | 296 | [[package]] 297 | name = "rand_core" 298 | version = "0.4.0" 299 | source = "registry+https://github.com/rust-lang/crates.io-index" 300 | 301 | [[package]] 302 | name = "rand_hc" 303 | version = "0.1.0" 304 | source = "registry+https://github.com/rust-lang/crates.io-index" 305 | dependencies = [ 306 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 307 | ] 308 | 309 | [[package]] 310 | name = "rand_isaac" 311 | version = "0.1.1" 312 | source = "registry+https://github.com/rust-lang/crates.io-index" 313 | dependencies = [ 314 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 315 | ] 316 | 317 | [[package]] 318 | name = "rand_jitter" 319 | version = "0.1.3" 320 | source = "registry+https://github.com/rust-lang/crates.io-index" 321 | dependencies = [ 322 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 323 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 324 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 325 | ] 326 | 327 | [[package]] 328 | name = "rand_os" 329 | version = "0.1.3" 330 | source = "registry+https://github.com/rust-lang/crates.io-index" 331 | dependencies = [ 332 | "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 333 | "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 334 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 335 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 336 | "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 337 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 338 | ] 339 | 340 | [[package]] 341 | name = "rand_pcg" 342 | version = "0.1.2" 343 | source = "registry+https://github.com/rust-lang/crates.io-index" 344 | dependencies = [ 345 | "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 346 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 347 | ] 348 | 349 | [[package]] 350 | name = "rand_xorshift" 351 | version = "0.1.1" 352 | source = "registry+https://github.com/rust-lang/crates.io-index" 353 | dependencies = [ 354 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 355 | ] 356 | 357 | [[package]] 358 | name = "rdrand" 359 | version = "0.4.0" 360 | source = "registry+https://github.com/rust-lang/crates.io-index" 361 | dependencies = [ 362 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 363 | ] 364 | 365 | [[package]] 366 | name = "redox_syscall" 367 | version = "0.1.54" 368 | source = "registry+https://github.com/rust-lang/crates.io-index" 369 | 370 | [[package]] 371 | name = "route-recognizer" 372 | version = "0.1.12" 373 | source = "registry+https://github.com/rust-lang/crates.io-index" 374 | 375 | [[package]] 376 | name = "router" 377 | version = "0.6.0" 378 | source = "registry+https://github.com/rust-lang/crates.io-index" 379 | dependencies = [ 380 | "iron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 381 | "route-recognizer 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 382 | "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", 383 | ] 384 | 385 | [[package]] 386 | name = "rustc_version" 387 | version = "0.2.3" 388 | source = "registry+https://github.com/rust-lang/crates.io-index" 389 | dependencies = [ 390 | "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 391 | ] 392 | 393 | [[package]] 394 | name = "safemem" 395 | version = "0.3.0" 396 | source = "registry+https://github.com/rust-lang/crates.io-index" 397 | 398 | [[package]] 399 | name = "semver" 400 | version = "0.9.0" 401 | source = "registry+https://github.com/rust-lang/crates.io-index" 402 | dependencies = [ 403 | "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 404 | ] 405 | 406 | [[package]] 407 | name = "semver-parser" 408 | version = "0.7.0" 409 | source = "registry+https://github.com/rust-lang/crates.io-index" 410 | 411 | [[package]] 412 | name = "siphasher" 413 | version = "0.2.3" 414 | source = "registry+https://github.com/rust-lang/crates.io-index" 415 | 416 | [[package]] 417 | name = "smallvec" 418 | version = "0.6.9" 419 | source = "registry+https://github.com/rust-lang/crates.io-index" 420 | 421 | [[package]] 422 | name = "time" 423 | version = "0.1.42" 424 | source = "registry+https://github.com/rust-lang/crates.io-index" 425 | dependencies = [ 426 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 427 | "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", 428 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 429 | ] 430 | 431 | [[package]] 432 | name = "traitobject" 433 | version = "0.1.0" 434 | source = "registry+https://github.com/rust-lang/crates.io-index" 435 | 436 | [[package]] 437 | name = "typeable" 438 | version = "0.1.2" 439 | source = "registry+https://github.com/rust-lang/crates.io-index" 440 | 441 | [[package]] 442 | name = "typemap" 443 | version = "0.3.3" 444 | source = "registry+https://github.com/rust-lang/crates.io-index" 445 | dependencies = [ 446 | "unsafe-any 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 447 | ] 448 | 449 | [[package]] 450 | name = "unicase" 451 | version = "1.4.2" 452 | source = "registry+https://github.com/rust-lang/crates.io-index" 453 | dependencies = [ 454 | "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 455 | ] 456 | 457 | [[package]] 458 | name = "unicode-bidi" 459 | version = "0.3.4" 460 | source = "registry+https://github.com/rust-lang/crates.io-index" 461 | dependencies = [ 462 | "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 463 | ] 464 | 465 | [[package]] 466 | name = "unicode-normalization" 467 | version = "0.1.8" 468 | source = "registry+https://github.com/rust-lang/crates.io-index" 469 | dependencies = [ 470 | "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", 471 | ] 472 | 473 | [[package]] 474 | name = "unsafe-any" 475 | version = "0.4.2" 476 | source = "registry+https://github.com/rust-lang/crates.io-index" 477 | dependencies = [ 478 | "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 479 | ] 480 | 481 | [[package]] 482 | name = "url" 483 | version = "1.7.2" 484 | source = "registry+https://github.com/rust-lang/crates.io-index" 485 | dependencies = [ 486 | "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 487 | "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 488 | "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 489 | ] 490 | 491 | [[package]] 492 | name = "version_check" 493 | version = "0.1.5" 494 | source = "registry+https://github.com/rust-lang/crates.io-index" 495 | 496 | [[package]] 497 | name = "winapi" 498 | version = "0.3.7" 499 | source = "registry+https://github.com/rust-lang/crates.io-index" 500 | dependencies = [ 501 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 502 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 503 | ] 504 | 505 | [[package]] 506 | name = "winapi-i686-pc-windows-gnu" 507 | version = "0.4.0" 508 | source = "registry+https://github.com/rust-lang/crates.io-index" 509 | 510 | [[package]] 511 | name = "winapi-x86_64-pc-windows-gnu" 512 | version = "0.4.0" 513 | source = "registry+https://github.com/rust-lang/crates.io-index" 514 | 515 | [metadata] 516 | "checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" 517 | "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" 518 | "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" 519 | "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" 520 | "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" 521 | "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" 522 | "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" 523 | "checksum colored 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e9a455e156a4271e12fd0246238c380b1e223e3736663c7a18ed8b6362028a9" 524 | "checksum fern 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)" = "29d26fa0f4d433d1956746e66ec10d6bf4d6c8b93cd39965cceea7f7cc78c7dd" 525 | "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" 526 | "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" 527 | "checksum hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)" = "df0caae6b71d266b91b4a83111a61d2b94ed2e2bea024c532b933dcff867e58c" 528 | "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" 529 | "checksum iron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d8e17268922834707e1c29e8badbf9c712c9c43378e1b6a3388946baff10be2" 530 | "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" 531 | "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" 532 | "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" 533 | "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" 534 | "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" 535 | "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" 536 | "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" 537 | "checksum mime_guess 1.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2d4c0961143b8efdcfa29c3ae63281601b446a4a668165454b6c90f8024954c5" 538 | "checksum modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58" 539 | "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" 540 | "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" 541 | "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" 542 | "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" 543 | "checksum phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" 544 | "checksum phf_codegen 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" 545 | "checksum phf_generator 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662" 546 | "checksum phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" 547 | "checksum plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a6a0dc3910bc8db877ffed8e457763b317cf880df4ae19109b9f77d277cf6e0" 548 | "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" 549 | "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" 550 | "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" 551 | "checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" 552 | "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" 553 | "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" 554 | "checksum rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9ea758282efe12823e0d952ddb269d2e1897227e464919a554f2a03ef1b832" 555 | "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" 556 | "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" 557 | "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" 558 | "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" 559 | "checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" 560 | "checksum route-recognizer 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3255338088df8146ba63d60a9b8e3556f1146ce2973bc05a75181a42ce2256" 561 | "checksum router 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc63b6f3b8895b0d04e816b2b1aa58fdba2d5acca3cbb8f0ab8e017347d57397" 562 | "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 563 | "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" 564 | "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 565 | "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" 566 | "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" 567 | "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" 568 | "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" 569 | "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" 570 | "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" 571 | "checksum typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6" 572 | "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" 573 | "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" 574 | "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" 575 | "checksum unsafe-any 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f" 576 | "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" 577 | "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" 578 | "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" 579 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 580 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 581 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mtmr0x_web_boilerplate" 3 | version = "0.0.1" 4 | authors = ["Matheus Marsiglio "] 5 | 6 | [dependencies] 7 | iron = "0.6.0" 8 | router = "0.6.0" 9 | log = "0.4" 10 | fern = { version = "0.5", features = ["colored"] } 11 | chrono = "0.4" 12 | rustc_version = "0.2.3" 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rust Web Server Boilerplate 2 | 3 | Start developing your Rust server based in this simple set up. 4 | 5 | - [Browse features](#features-list) to understand better what you can find in here; 6 | - [Check table of contents](#table-of-contents) for full documentation. 7 | 8 | The following instructions are for MacOS or Linux. 9 | 10 | If something doesn't work, open an issue or open a Pull Request following [contribution guidelines](https://github.com/mtmr0x/rust-web-boilerplate/blob/master/CONTRIBUTING.md); 11 | 12 | ## Quick overview 13 | 14 | ```sh 15 | # copy env sample file to .env file 16 | cp ./.env.sample ./.env 17 | 18 | # open it and replace its values 19 | vim ./.env 20 | ``` 21 | 22 | Follow [env files section](#environment-variables) for understanding it. 23 | 24 | Then start the server using the `start.sh` script. 25 | 26 | ```sh 27 | ./start.sh # make sure you gave permissions to it 28 | ``` 29 | 30 | ## Table of contents 31 | 32 | - [Installation](#installation) 33 | - [Set up](#set-up) 34 | - [Environment variables](#environment-variables) 35 | - [Run](#run) 36 | - [Features](#features) 37 | - [Logger](#logger) 38 | - [Configuration](#configuration) 39 | - [Routing](#routing) 40 | 41 | ### Installation 42 | 43 | Install Rust 44 | 45 | Go to https://www.rust-lang.org/tools/install and check installation methods 46 | 47 | > Note: this project is set with version 1.34.1 and tested with 1.29.0 and worked pretty well. You can define your version of Rust at your [environment variables](#environment-variables). 48 | 49 | ### Set up 50 | 51 | #### Environment variables 52 | 53 | For properly run this project, you will have to set some environment variables. Everything you need to set up is located in [.env.sample file](https://github.com/mtmr0x/rust-web-boilerplate/blob/master/.env.sample). 54 | 55 | > Every update in your `.env` file you must add the new variable to the process at your start up script before running it. Open and edit the `start.sh` file present in the root directory of this project. 56 | 57 | ### Run 58 | 59 | Execute the `start.sh` script located in the this project: 60 | 61 | ```shell 62 | ./start.sh 63 | ``` 64 | 65 | ### Features 66 | 67 | #### Logger 68 | 69 | Logger configurations depends on `LEVEL_VERBOSITY` environment variable for deciding what levels of logs can be printed. `LEVEL_VERBOSITY` documentation and usage is present in `.env.sample` file. 70 | 71 | **stdout log**: 72 | 73 | The application logs stdout for instrumentation and its format is present in `src/logger/logger.rs` file, logging hour, target, level and message. 74 | 75 | **output file log**: 76 | 77 | The file output is set as `output.log` file, that will be present in the root directory as it has logs. It prints the same format of stdout logs with addition of Year, Month and Day of that output before the time of it. 78 | 79 | #### Configuration 80 | 81 | This application tries to follow _configuration over convention_. All types of configurations that is not Rust convention is placed as environment variable and all of them must be set, otherwise the application will fail to start. 82 | 83 | You can find all necessary environment variables documented for this project inside `.env.sample` file. 84 | 85 | #### Routing 86 | 87 | This project is meant to be easy for people coming from NodeJS and that said the closest way to get there was to find a routing declaration library and framework that could make web development similar to ExpressJS or Koa. [Iron](https://docs.rs/iron/0.6.0/iron/index.html) and [Router](https://docs.rs/router/0.6.0/router/index.html) did the job. 88 | 89 | 90 | ## To-do list 91 | 92 | - [x] Web framework (Iron): https://docs.rs/iron/0.6.0/iron/index.html 93 | - [x] Routing: https://docs.rs/router/0.6.0/router/index.html 94 | - [x] Get environment variables from profile 95 | - [x] Have a sexy log tool great for instrumentation 96 | - [x] Document how to run 97 | - [ ] Implement GraphQL 98 | 99 | -------------------------------------------------------------------------------- /src/config.rs: -------------------------------------------------------------------------------- 1 | pub mod config { 2 | use std::env; 3 | use std::option::Option; 4 | 5 | fn get_env_var(key: String) -> Option { 6 | match env::var(key) { 7 | Ok(val) => Some(val), 8 | Err(_e) => None, 9 | } 10 | } 11 | 12 | pub fn server_port() -> String { 13 | get_env_var("SERVER_PORT".to_string()).unwrap() 14 | } 15 | 16 | pub fn level_verbosity() -> u8 { 17 | let value:String = get_env_var("LEVEL_VERBOSITY".to_string()).unwrap(); 18 | value.parse::().unwrap() 19 | } 20 | 21 | pub fn rustc_version() -> String { 22 | get_env_var("RUSTC_VERSION".to_string()).unwrap() 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/endpoints/index.rs: -------------------------------------------------------------------------------- 1 | extern crate iron; 2 | extern crate router; 3 | 4 | use iron::{Request, Response, IronResult}; 5 | use iron::status; 6 | 7 | pub fn index_handler(_req: &mut Request) -> IronResult { 8 | info!("responding index"); 9 | Ok(Response::with((status::Ok, "Hello world".to_string()))) 10 | } 11 | 12 | -------------------------------------------------------------------------------- /src/endpoints/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod index; 2 | -------------------------------------------------------------------------------- /src/logger/logger.rs: -------------------------------------------------------------------------------- 1 | extern crate log; 2 | extern crate chrono; 3 | extern crate fern; 4 | 5 | use std::io; 6 | use fern::colors::{Color, ColoredLevelConfig}; 7 | 8 | pub fn setup_logger(verbosity:u8) -> Result<(), fern::InitError> { 9 | let mut level_config = fern::Dispatch::new(); 10 | 11 | level_config = match verbosity { 12 | 0 => level_config.level(log::LevelFilter::Warn), 13 | 1 => level_config.level(log::LevelFilter::Info), 14 | _2_or_more => level_config.level(log::LevelFilter::Debug), 15 | }; 16 | 17 | let colors = ColoredLevelConfig::new() 18 | .info(Color::Green) 19 | .error(Color::Red) 20 | .warn(Color::Yellow) 21 | .debug(Color::Magenta); 22 | 23 | let file_config = fern::Dispatch::new() 24 | .format(move |out, message, record| { 25 | out.finish(format_args!( 26 | "{}[{}][{}] {}", 27 | chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"), 28 | record.target(), 29 | colors.color(record.level()), 30 | message 31 | )) 32 | }) 33 | .chain(fern::log_file("output.log")?); 34 | 35 | let stdout_config = fern::Dispatch::new() 36 | .format(move |out, message, record| { 37 | out.finish(format_args!( 38 | "{}[{}][{}] {}", 39 | chrono::Local::now().format("[%H:%M:%S]"), 40 | record.target(), 41 | colors.color(record.level()), 42 | message 43 | )) 44 | }) 45 | .chain(io::stdout()); 46 | 47 | level_config.chain(file_config).chain(stdout_config).apply()?; 48 | 49 | Ok(()) 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/logger/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod logger; 2 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate rustc_version; 2 | extern crate iron; 3 | extern crate router; 4 | extern crate fern; 5 | #[macro_use] 6 | extern crate log; 7 | 8 | use std::io::{self, Write}; 9 | use std::process::exit; 10 | use rustc_version::{version, Version}; 11 | 12 | use iron::{Iron}; 13 | 14 | mod endpoints; 15 | mod config; 16 | use config::config::{server_port, level_verbosity, rustc_version}; 17 | mod logger; 18 | use logger::logger::setup_logger; 19 | 20 | mod routes; 21 | use routes::routes::app_routes; 22 | 23 | fn main() { 24 | if version().unwrap() != Version::parse(&rustc_version()).unwrap() { 25 | writeln!(&mut io::stderr(), "This crate requires rustc version {} but found {}", rustc_version(), version().unwrap()).unwrap(); 26 | exit(1); 27 | } 28 | 29 | setup_logger(level_verbosity()).expect("Could not load logger"); 30 | info!("Loading server"); 31 | 32 | let server_url:String = format!("0.0.0.0:{}", server_port()); 33 | 34 | info!("server is running at {}", server_url); 35 | Iron::new(app_routes()).http(server_url).unwrap(); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/routes.rs: -------------------------------------------------------------------------------- 1 | pub mod routes { 2 | extern crate router; 3 | use router::Router; 4 | 5 | use endpoints::index::index_handler; 6 | 7 | pub fn app_routes() -> Router { 8 | let mut router = Router::new(); 9 | 10 | router.get("/", index_handler, "index"); 11 | 12 | router 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | source .env 4 | 5 | RUSTC_VERSION=$RUSTC_VERSION \ 6 | LEVEL_VERBOSITY=$LEVEL_VERBOSITY \ 7 | SERVER_PORT=$SERVER_PORT \ 8 | ~/.cargo/bin/cargo run 9 | 10 | --------------------------------------------------------------------------------