├── .cargo └── config.toml ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── pull_request_template.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── Makefile.toml ├── README.md ├── cargo-generate.toml ├── src ├── deno_sys │ └── mod.rs ├── index.ts └── lib.rs └── tests ├── integration.ts └── mod.rs /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [target.wasm32-unknown-unknown] 2 | runner = 'wasm-bindgen-test-runner' 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | Please include a summary of the change and which issue is fixed. 4 | Please also include relevant motivation and context. 5 | 6 | # Type of change 7 | 8 | - [ ] 🚀 Feature 9 | - [ ] 🐛 Fix 10 | - [ ] 🛠️ Tooling 11 | - [ ] 🧪 Test 12 | - [ ] 📦 Dependency 13 | - [ ] 📖 Requires documentation update 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .vscode 3 | build -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | yoav@yoavlavi.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thank you for considering contributing to `deno-deploy-rust-template`! 4 | 5 | ## Pull Requests 6 | 7 | To create a new pull request: 8 | 9 | - Fork this repository and creating a new branch from `main` 10 | - Add your code changes 11 | - Add tests if relevant 12 | - Change / add documentation as needed 13 | - Make sure to lint your code and run the test suit (on a generated project) 14 | 15 | When you're done, submit your pull request! 16 | 17 | ## Issues 18 | 19 | Request a new feature or report a bug by [opening a new issue](https://github.com/yoav-lavi/deno-deploy-rust-template/issues) 20 | 21 | ## License 22 | 23 | By contributing, you agree that your contributions will be licensed under its MIT License. 24 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "bumpalo" 7 | version = "3.10.0" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" 10 | 11 | [[package]] 12 | name = "cfg-if" 13 | version = "1.0.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 16 | 17 | [[package]] 18 | name = "console_error_panic_hook" 19 | version = "0.1.7" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" 22 | dependencies = [ 23 | "cfg-if", 24 | "wasm-bindgen", 25 | ] 26 | 27 | [[package]] 28 | name = "js-sys" 29 | version = "0.3.58" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" 32 | dependencies = [ 33 | "wasm-bindgen", 34 | ] 35 | 36 | [[package]] 37 | name = "lazy_static" 38 | version = "1.4.0" 39 | source = "registry+https://github.com/rust-lang/crates.io-index" 40 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 41 | 42 | [[package]] 43 | name = "log" 44 | version = "0.4.17" 45 | source = "registry+https://github.com/rust-lang/crates.io-index" 46 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" 47 | dependencies = [ 48 | "cfg-if", 49 | ] 50 | 51 | [[package]] 52 | name = "proc-macro2" 53 | version = "1.0.40" 54 | source = "registry+https://github.com/rust-lang/crates.io-index" 55 | checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" 56 | dependencies = [ 57 | "unicode-ident", 58 | ] 59 | 60 | [[package]] 61 | name = "project_name" 62 | version = "0.1.0" 63 | dependencies = [ 64 | "console_error_panic_hook", 65 | "js-sys", 66 | "wasm-bindgen", 67 | "wasm-bindgen-futures", 68 | "wasm-bindgen-test", 69 | "web-sys", 70 | ] 71 | 72 | [[package]] 73 | name = "quote" 74 | version = "1.0.20" 75 | source = "registry+https://github.com/rust-lang/crates.io-index" 76 | checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" 77 | dependencies = [ 78 | "proc-macro2", 79 | ] 80 | 81 | [[package]] 82 | name = "scoped-tls" 83 | version = "1.0.0" 84 | source = "registry+https://github.com/rust-lang/crates.io-index" 85 | checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" 86 | 87 | [[package]] 88 | name = "syn" 89 | version = "1.0.98" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" 92 | dependencies = [ 93 | "proc-macro2", 94 | "quote", 95 | "unicode-ident", 96 | ] 97 | 98 | [[package]] 99 | name = "unicode-ident" 100 | version = "1.0.2" 101 | source = "registry+https://github.com/rust-lang/crates.io-index" 102 | checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" 103 | 104 | [[package]] 105 | name = "wasm-bindgen" 106 | version = "0.2.81" 107 | source = "registry+https://github.com/rust-lang/crates.io-index" 108 | checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" 109 | dependencies = [ 110 | "cfg-if", 111 | "wasm-bindgen-macro", 112 | ] 113 | 114 | [[package]] 115 | name = "wasm-bindgen-backend" 116 | version = "0.2.81" 117 | source = "registry+https://github.com/rust-lang/crates.io-index" 118 | checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" 119 | dependencies = [ 120 | "bumpalo", 121 | "lazy_static", 122 | "log", 123 | "proc-macro2", 124 | "quote", 125 | "syn", 126 | "wasm-bindgen-shared", 127 | ] 128 | 129 | [[package]] 130 | name = "wasm-bindgen-futures" 131 | version = "0.4.31" 132 | source = "registry+https://github.com/rust-lang/crates.io-index" 133 | checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" 134 | dependencies = [ 135 | "cfg-if", 136 | "js-sys", 137 | "wasm-bindgen", 138 | "web-sys", 139 | ] 140 | 141 | [[package]] 142 | name = "wasm-bindgen-macro" 143 | version = "0.2.81" 144 | source = "registry+https://github.com/rust-lang/crates.io-index" 145 | checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" 146 | dependencies = [ 147 | "quote", 148 | "wasm-bindgen-macro-support", 149 | ] 150 | 151 | [[package]] 152 | name = "wasm-bindgen-macro-support" 153 | version = "0.2.81" 154 | source = "registry+https://github.com/rust-lang/crates.io-index" 155 | checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" 156 | dependencies = [ 157 | "proc-macro2", 158 | "quote", 159 | "syn", 160 | "wasm-bindgen-backend", 161 | "wasm-bindgen-shared", 162 | ] 163 | 164 | [[package]] 165 | name = "wasm-bindgen-shared" 166 | version = "0.2.81" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" 169 | 170 | [[package]] 171 | name = "wasm-bindgen-test" 172 | version = "0.3.31" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | checksum = "68b30cf2cba841a812f035c40c50f53eb9c56181192a9dd2c71b65e6a87a05ba" 175 | dependencies = [ 176 | "console_error_panic_hook", 177 | "js-sys", 178 | "scoped-tls", 179 | "wasm-bindgen", 180 | "wasm-bindgen-futures", 181 | "wasm-bindgen-test-macro", 182 | ] 183 | 184 | [[package]] 185 | name = "wasm-bindgen-test-macro" 186 | version = "0.3.31" 187 | source = "registry+https://github.com/rust-lang/crates.io-index" 188 | checksum = "88ad594bf33e73cafcac2ae9062fc119d4f75f9c77e25022f91c9a64bd5b6463" 189 | dependencies = [ 190 | "proc-macro2", 191 | "quote", 192 | ] 193 | 194 | [[package]] 195 | name = "web-sys" 196 | version = "0.3.58" 197 | source = "registry+https://github.com/rust-lang/crates.io-index" 198 | checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" 199 | dependencies = [ 200 | "js-sys", 201 | "wasm-bindgen", 202 | ] 203 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "{{project-name}}" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | crate-type = ["cdylib", "rlib"] 8 | 9 | [dependencies] 10 | web-sys = { version = "0.3", features = [ 11 | "Headers", 12 | "Request", 13 | "RequestInit", 14 | "RequestMode", 15 | "Response", 16 | "FormData", 17 | "Blob", 18 | "BlobPropertyBag", 19 | ] } 20 | wasm-bindgen = "0.2" 21 | wasm-bindgen-futures = "0.4" 22 | console_error_panic_hook = "0.1" 23 | js-sys = "0.3.58" 24 | 25 | [dev-dependencies] 26 | wasm-bindgen-test = "0.3" 27 | 28 | [profile.release] 29 | opt-level = "s" 30 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all 9 | copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 | SOFTWARE. 18 | -------------------------------------------------------------------------------- /Makefile.toml: -------------------------------------------------------------------------------- 1 | [tasks.install-wasm-bindgen] 2 | install_crate = { crate_name = "wasm-bindgen-cli", binary = "wasm-bindgen", test_arg = "--help" } 3 | 4 | [tasks.install-deno] 5 | install_crate = { crate_name = "deno", binary = "deno", test_arg = "--help" } 6 | 7 | [tasks.install-deployctl] 8 | install_script = ''' 9 | deno install --allow-read --allow-write --allow-env --allow-net --allow-run --no-check --force https://deno.land/x/deploy/deployctl.ts 10 | ''' 11 | ignore_errors = true 12 | 13 | [tasks.add-wasm32-target] 14 | command = "rustup" 15 | args = ["target", "add", "wasm32-unknown-unknown"] 16 | 17 | [tasks.cargo-build] 18 | command = "cargo" 19 | args = ["build", "--release", "--target", "wasm32-unknown-unknown"] 20 | 21 | [tasks.wasm-bindgen] 22 | command = "wasm-bindgen" 23 | args = [ 24 | "target/wasm32-unknown-unknown/release/{{crate_name}}.wasm", 25 | "--target", 26 | "deno", 27 | "--out-dir", 28 | "build/", 29 | ] 30 | 31 | [tasks.build-wasm] 32 | dependencies = [ 33 | "add-wasm32-target", 34 | "install-wasm-bindgen", 35 | "install-deno", 36 | "install-deployctl", 37 | "cargo-build", 38 | "wasm-bindgen", 39 | ] 40 | 41 | [tasks.run-deployctl] 42 | command = "deployctl" 43 | args = [ 44 | "deploy", 45 | "--project={{deno-deploy-project-name}}", 46 | "src/index.ts", 47 | "--exclude", 48 | "target/", 49 | ] 50 | 51 | [tasks.run-with-deno] 52 | command = "deno" 53 | args = ["run", "--allow-read", "--allow-net", "--allow-env", "src/index.ts"] 54 | 55 | [tasks.deploy] 56 | dependencies = ["build-wasm", "install-deployctl", "run-deployctl"] 57 | 58 | [tasks.run] 59 | dependencies = ["build-wasm", "run-with-deno"] 60 | 61 | [tasks.test-rust] 62 | command = "cargo" 63 | args = ["test", "--target", "wasm32-unknown-unknown"] 64 | 65 | [tasks.test-integration] 66 | dependencies = ["build-wasm"] 67 | command = "deno" 68 | args = ["test", "--allow-read", "--allow-net", "tests/integration.ts"] 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

3 | deno-deploy-rust-template 4 |

5 |
6 | 7 |

8 | A template for creating Deno Deploy projects in Rust 9 |

10 | 11 | ## Prerequisites 12 | 13 | - [`cargo-generate`](https://github.com/cargo-generate/cargo-generate) 14 | - [`cargo-make`](https://github.com/sagiegurari/cargo-make#installation) 15 | 16 |
17 | Prerequisites for usage without cargo-make 18 |
19 | 25 |
26 | 27 | ## Usage 28 | 29 | > **Note** 30 | > 31 | > If using `cargo make`, any commands requiring `deno` will attempt to install `deno` via `cargo`, if it is not already installed and in your `$PATH`. 32 | > If you want to install `deno` via other means and haven't already, do so before running any `cargo make` commands. 33 | 34 | ### Using this template 35 | 36 | ```sh 37 | cargo generate gh:yoav-lavi/deno-deploy-rust-template 38 | ``` 39 | 40 | ### Building your project 41 | 42 | ```sh 43 | cargo make build-wasm 44 | ``` 45 | 46 |
47 | Manual command 48 |
49 |
rustup target add wasm32-unknown-unknown
&& cargo build --release --target wasm32-unknown-unknown
&& wasm-bindgen target/wasm32-unknown-unknown/release/{{crate_name}}.wasm --target deno --out-dir build/
50 |
51 | 52 | ### Deploying to Deno Deploy 53 | 54 | > **Note** 55 | > 56 | > Create a new token in the Deno Deploy (under "Access Tokens") and use it in place of `...` in `DENO_DEPLOY_TOKEN=...` 57 | > 58 | > If `~/.deno/bin` is not in your `$PATH`, you will need to add it for this command to work 59 | 60 | ```sh 61 | DENO_DEPLOY_TOKEN=... cargo make deploy 62 | ``` 63 | 64 |
65 | Manual command 66 |
67 |
deployctl deploy --token=... --project={{deno-deploy-project-name}} src/index.ts --exclude "target/"
68 |
69 | 70 | ### Running your project with Deno 71 | 72 | ```sh 73 | cargo make run 74 | ``` 75 | 76 |
77 | Manual command 78 |
79 |
deno run --allow-read --allow-net --allow-env src/index.ts
80 |
81 | 82 | ### Running tests 83 | 84 | ```sh 85 | cargo make test-rust 86 | cargo make test-integration 87 | ``` 88 | 89 |
90 | Manual command 91 |
92 |
cargo test --target wasm32-unknown-unknown
deno test --allow-read --allow-net --allow-env tests/integration.ts
93 |
94 | 95 | -------------------------------------------------------------------------------- /cargo-generate.toml: -------------------------------------------------------------------------------- 1 | [placeholders.deno-deploy-project-name] 2 | type = "string" 3 | prompt = "What's your Deno Deploy project name? (create an empty project if you don't have one)" 4 | 5 | [template] 6 | ignore = [ 7 | "LICENSE-MIT", 8 | "LICENSE-APACHE", 9 | "CODE_OF_CONDUCT.md", 10 | ".github/", 11 | "CONTRIBUTING.md", 12 | ] 13 | -------------------------------------------------------------------------------- /src/deno_sys/mod.rs: -------------------------------------------------------------------------------- 1 | /// The global `Deno` object 2 | /// 3 | /// [Deno documentation](https://doc.deno.land/deno/stable/~/Deno) 4 | #[allow(non_snake_case)] 5 | pub mod Deno { 6 | use js_sys::Object; 7 | use wasm_bindgen::prelude::*; 8 | 9 | #[wasm_bindgen] 10 | extern "C" { 11 | /// The `env` variable on the global `Deno` object. 12 | /// 13 | /// Allows to get, set and delete environment variables 14 | /// 15 | /// [Deno documentation](https://doc.deno.land/deno/stable/~/Deno.env) 16 | #[allow(non_camel_case_types)] 17 | #[wasm_bindgen(js_namespace = Deno, extends = Object)] 18 | #[derive(Clone, Debug)] 19 | pub type env; 20 | 21 | #[wasm_bindgen(js_namespace = Deno, static_method_of = env)] 22 | pub fn get(key: String) -> Option; 23 | 24 | #[wasm_bindgen(js_namespace = Deno, static_method_of = env)] 25 | pub fn set(key: String, value: String); 26 | 27 | #[wasm_bindgen(js_namespace = Deno, static_method_of = env)] 28 | pub fn delete(delete: String); 29 | 30 | #[wasm_bindgen(js_namespace = Deno, static_method_of = env, js_name = toObject)] 31 | pub fn to_object() -> Object; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { serve } from "https://deno.land/std@0.142.0/http/server.ts"; 2 | import { handler } from "../build/{{crate_name}}.js"; 3 | 4 | serve(handler); 5 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | mod deno_sys; 2 | 3 | use wasm_bindgen::prelude::*; 4 | use web_sys::{Request, Response}; 5 | 6 | #[wasm_bindgen] 7 | pub async fn handler(_request: Request) -> Result { 8 | console_error_panic_hook::set_once(); 9 | Response::new_with_opt_str(Some("hello world!")) 10 | } 11 | -------------------------------------------------------------------------------- /tests/integration.ts: -------------------------------------------------------------------------------- 1 | import { assertStrictEquals } from "https://deno.land/std@0.146.0/testing/asserts.ts"; 2 | import "../src/index.ts"; 3 | 4 | Deno.test({ 5 | name: "Integration", 6 | fn: async () => { 7 | const response = await fetch("http://localhost:8000", { 8 | method: "POST", 9 | }); 10 | assertStrictEquals(await response.text(), "hello world!"); 11 | }, 12 | sanitizeResources: false, 13 | sanitizeOps: false, 14 | }); 15 | -------------------------------------------------------------------------------- /tests/mod.rs: -------------------------------------------------------------------------------- 1 | use {{crate_name}}::handler; 2 | use wasm_bindgen_test::*; 3 | use web_sys::{Request, RequestInit}; 4 | 5 | #[wasm_bindgen_test] 6 | async fn handler_test() { 7 | let mut request_init = RequestInit::new(); 8 | 9 | request_init.method("POST"); 10 | 11 | let request = Request::new_with_str_and_init("http://localhost:8000", &request_init).unwrap(); 12 | 13 | let response = handler(request).await.unwrap(); 14 | 15 | let response_body = wasm_bindgen_futures::JsFuture::from(response.text().unwrap()) 16 | .await 17 | .unwrap() 18 | .as_string(); 19 | 20 | assert_eq!(response_body, Some("hello world!".to_owned())); 21 | } 22 | --------------------------------------------------------------------------------