Skip to content

Commit 6adf264

Browse files
authored
feat: add warp integration (#86)
* refactor: moved some functions for integrations into the core package This will make developing more integrations in future much simpler. This also involved standardizing the `Options` taken by all integrations BREAKING CHANGE: `Options` renamed to `ServerOptions` for all integrations * feat: made templates and error pages thread-safe This involved adding an atomic types system. Also added basics for a Warp integration (which needs this thread-safety). * feat: made more things thread-safe and made warp integration nearly work The problem is `Rc<Translator>`s, so some refactoring needs to be done. * feat: added nearly all handlers to warp integration BREAKING_CHANGE: `ServerOptions` now only accepts one static content directory * fix: made `DummyTranslator` `Clone`able * feat: added support for static aliases in the warp integration None of this has been tested yet, so there will likely be bugs. We now depend on my fork of Warp until [this](seanmonstar/warp#924) is merged. * fix: pinned `clap` version Fixes #85. * feat: finalized warp integration It's also now the default in the CLI. * docs: updated docs to reflect warp integration * docs: merged `next` and `0.3.x` docs * chore: extended version replacement script Now covers the `Cargo.toml` files in `examples/basic/.perseus`.
1 parent 45d676e commit 6adf264

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1254
-398
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ These tasks still need to be done before Perseus can be pushed to v1.0.0.
6464
* [ ] Support custom template hierarchies
6565
* [ ] Pre-built integrations
6666
- [x] Actix Web
67+
- [x] Warp
6768
- [ ] AWS Lambda
6869

6970
### Beyond

bonnie.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ release.cmd = [
191191
"git checkout stable"
192192
]
193193
release.desc = "creates a new project release and pushes it to github (cargo version must be manually bumped, needs branch 'stable')"
194-
replace-versions.cmd = "find . \\( -name \"*Cargo.toml\" -or -name \"*Cargo.toml.example\" -or -name \"*.md\" \\) -not -name \"CHANGELOG.md\" -not -path \"./target/*\" -not -path \"./website/*\" -not -path \"*.perseus*\" -exec sed -i -e 's/%old_version/%new_version/g' {} \\;"
194+
replace-versions.cmd = "find . \\( -name \"*Cargo.toml\" -or -name \"*Cargo.toml.example\" -or -name \"*.md\" \\) -not -name \"CHANGELOG.md\" -not -path \"./target/*\" -not -path \"./website/*\" -not -path \"*.perseus*\" -or \\( -name \"*Cargo.toml\" -path \"./examples/basic/.perseus/*\" -not -path \"./examples/basic/.perseus/dist/*\" \\) -exec sed -i -e 's/%old_version/%new_version/g' {} \\;"
195195
replace-versions.args = [ "old_version", "new_version" ]
196196

197197
# Publishes each package

docs/0.3.x/en-US/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [State Amalgamation](/docs/strategies/amalgamation)
3232
- [CLI](/docs/cli)
3333
- [Ejecting](/docs/ejecting)
34+
- [Snooping](/docs/snooping)
3435
- [Testing](/docs/testing/intro)
3536
- [Checkpoints](/docs/testing/checkpoints)
3637
- [Fantoccini Basics](/docs/testing/fantoccini-basics)
@@ -52,6 +53,7 @@
5253
- [Optimizing Code Size](/docs/deploying/size)
5354
- [Relative Paths](/docs/deploying/relative-paths)
5455
- [Migrating from v0.2.x](/docs/updating)
56+
- [Common Pitfalls and Known Bugs](/docs/pitfalls-and-bugs)
5557

5658
---
5759

docs/0.3.x/en-US/advanced/arch.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Architecture
22

3-
Perseus has five main components:
3+
Perseus has several main components:
44

55
- `perseus` -- the core module that defines everything necessary to build a Perseus app if you try hard enough
66
- `perseus-actix-web` -- an integration that makes it easy to run Perseus on the [Actix Web](https://actix.rs) framework
7+
- `perseus-warp` -- an integration that makes it easy to run Perseus on the [Warp](https://github.com/seanmonstar/warp) framework
78
- `perseus-cli` -- the command-line interface used to run Perseus apps conveniently
89
- `perseus-engine` -- an internal crate created by the CLI responsible for building an app
910
- `perseus-engine-server` -- an internal crate created by the CLI responsible for serving an app and performing runtime logic

docs/0.3.x/en-US/hello-world.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ Finally, we tell Perseus what to do if something in your app fails, like if the
6161

6262
</details>
6363

64-
Now, tell Rust that you want to be compiling for WebAssembly by adding that platform as a target. You can do this by running `rustup target add wasm32-unknown-unknown`.
65-
66-
After that's finished, you can install the Perseus CLI with `cargo install perseus-cli --version 0.3.0-beta.18` (you'll need `wasm-pack` to let Perseus build your app, use `cargo install wasm-pack` to install it) to make your life way easier, and deploy your app to <http://localhost:8080> by running `perseus serve` inside the root of your project! This will take a while the first time, because it's got to fetch all your dependencies and build your app.
64+
Now install the Perseus CLI with `cargo install perseus-cli` (you'll need `wasm-pack` to let Perseus build your app, use `cargo install wasm-pack` to install it) to make your life way easier, and deploy your app to <http://localhost:8080> by running `perseus serve` inside the root of your project! This will take a while the first time, because it's got to fetch all your dependencies and build your app.
6765

6866
<details>
6967
<summary>Why do I need a CLI?</summary>

docs/0.3.x/en-US/pitfalls-and-bugs.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Common Pitfalls and Known Bugs
2+
3+
This document is a list of common pitfalls and known bugs in Perseus, and will be updated regularly. If you're having an issue with Perseus, check through this list to see if your problem already has a solution.
4+
5+
## `perseus serve` fails with no error message on Arch Linux
6+
7+
If you're running Arch Linux or a derivative (e.g. Manjaro), you're very likely to encounter a bug in which `perseus serve` stops with no error messages whatsoever, and your app doesn't build properly. This is tracked by [issue #78](https://github.com/arctic-hen7/perseus/issues/78), and is due to an issue in OpenSSL that causes a segmentation fault in `wasm-pack` (see [this issue](https://github.com/rustwasm/wasm-pack/issues/1079)). Right now, the only solution to this is to downgrade `wasm-pack` by running `cargo install wasm-pack --version "0.9.1"`, which seems to fix the problem.

docs/0.3.x/en-US/snooping.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Snooping on the CLI
2+
3+
Most of the time, it's fine to run `perseus serve` and enjoy the results, but sometimes you'll need to delve a little deeper and see some more detailed logs. Then you need `perseus snoop`. This command will run one of the lower-level steps the Perseus CLI runs, but in such a way that you can see everything it does. The time you'll use this the most is when you have a `dbg!()` call in the static generation process (e.g. in the *build state* strategy) and you want to actually see its output, which neither `perseus build` nor `perseus serve` will let you do.
4+
5+
## `perseus snoop build`
6+
7+
This snoops on the static generation process, which is half of what `perseus build` does. You can use this to see the outputs of `dbg!()` calls in your build-time code.
8+
9+
## `perseus snoop wasm-build`
10+
11+
This snoops on the `wasm-pack` call that compiles your app to Wasm. There aren't really any use cases for this outside debugging strange errors, because Perseus calls out to this process without augmenting it in any way, so your code shouldn't impact this really at all (unless you're using some package that can't be compiled to Wasm).
12+
13+
## `perseus snoop serve`
14+
15+
This snoops on the server, which is useful if you're hacking on it, or if you're getting errors from it (e.g. panics in the server will only appear if you run this). Crucially though, this expects to be working with a correct build state, which means **you must run `perseus build` before running this command**, otherwise all sorts of things could happen. If such things do happen, you should run `perseus clean --dist`, and that should solve things.

docs/0.3.x/en-US/strategies/request-state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Note that, just like _build state_, this strategy generates stringified properti
1717
<details>
1818
<summary>How do you get the user's request information?</summary>
1919

20-
[Actix Web](https://actix.rs) (and any other framework worth its salt) automatically passes this information to handlers like Perseus. The slightly difficult thing is then converting this from Actix's custom format to Perseus' (which is just an alias for the [`http`](https://docs.rs/http) module's). This is done in the [`perseus-actix-web`](https://docs.rs/perseus-actix-web) crate.
20+
The web frameworks Perseus supports automatically pass this information to handlers like Perseus. The slightly difficult thing is then converting this from their custom format to Perseus' (which is just an alias for the [`http`](https://docs.rs/http) module's). This is done in the appropriate integration crate.
2121

2222
</details>
2323

docs/0.3.x/en-US/what-is-perseus.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
If you're familiar with [NextJS](https://nextjs.org), Perseus is that for Wasm. If you're familiar with [SvelteKit](https://kit.svelte.dev), it's that for [Sycamore](https://github.com/sycamore-rs/sycamore).
44

5-
If none of that makes any sense, this is the section for you! If you're not in the mood for a lecture, [here's a TL;DR](#summary)!
5+
If none of that makes any sense, this is the section for you! If you're not in the mood for a lecture, there's a TL;DR at the bottom of this page!
66

77
### Rust web development
88

@@ -60,7 +60,7 @@ To our knowledge, the only other framework in the world right now that supports
6060

6161
## How fast is it?
6262

63-
[Benchmarks show](https://rawgit.com/krausest/js-framework-benchmark/master/webdriver-ts-results/table.html) that [Sycamore](https://sycamore-rs.netlify.app) is slightly faster than [Svelte](https://svelte.dev) in places, one of the fastest JS frameworks ever. Perseus uses it and [Actix Web](https://actix.rs), one of the fastest web servers in the world. Essentially, Perseus is built on the fastest tech and is itself made to be fast.
63+
[Benchmarks show](https://rawgit.com/krausest/js-framework-benchmark/master/webdriver-ts-results/table.html) that [Sycamore](https://sycamore-rs.netlify.app) is slightly faster than [Svelte](https://svelte.dev) in places, one of the fastest JS frameworks ever. Perseus uses it and [Actix Web](https://actix.rs) or [Warp](https://github.com/seanmonstar/warp) (either is supported), some of the fastest web servers in the world. Essentially, Perseus is built on the fastest tech and is itself made to be fast.
6464

6565
The speed of web frameworks is often measured by [Lighthouse](https://developers.google.com/web/tools/lighthouse) scores, which are scores out of 100 (higher is better) that measure a whole host of things, like *total blocking time*, *first contentful paint*, and *time to interactive*. These are then aggregated into a final score and grouped into three brackets: 0-49 (slow), 50-89 (medium), and 90-100 (fast). This website, which is built with Perseus, using [static exporting](:exporting) and [size optimizations](:deploying/size), consistently scores a 100 on desktop and above 90 for mobile. You can see this for yourself [here](https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Farctic-hen7.github.io%2Fperseus%2Fen-US%2F&tab=desktop) on Google's PageSpeed Insights tool.
6666

docs/next/en-US/advanced/arch.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Architecture
22

3-
Perseus has five main components:
3+
Perseus has several main components:
44

55
- `perseus` -- the core module that defines everything necessary to build a Perseus app if you try hard enough
66
- `perseus-actix-web` -- an integration that makes it easy to run Perseus on the [Actix Web](https://actix.rs) framework
7+
- `perseus-warp` -- an integration that makes it easy to run Perseus on the [Warp](https://github.com/seanmonstar/warp) framework
78
- `perseus-cli` -- the command-line interface used to run Perseus apps conveniently
89
- `perseus-engine` -- an internal crate created by the CLI responsible for building an app
910
- `perseus-engine-server` -- an internal crate created by the CLI responsible for serving an app and performing runtime logic

docs/next/en-US/strategies/request-state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Note that, just like _build state_, this strategy generates stringified properti
1717
<details>
1818
<summary>How do you get the user's request information?</summary>
1919

20-
[Actix Web](https://actix.rs) (and any other framework worth its salt) automatically passes this information to handlers like Perseus. The slightly difficult thing is then converting this from Actix's custom format to Perseus' (which is just an alias for the [`http`](https://docs.rs/http) module's). This is done in the [`perseus-actix-web`](https://docs.rs/perseus-actix-web) crate.
20+
The web frameworks Perseus supports automatically pass this information to handlers like Perseus. The slightly difficult thing is then converting this from their custom format to Perseus' (which is just an alias for the [`http`](https://docs.rs/http) module's). This is done in the appropriate integration crate.
2121

2222
</details>
2323

docs/next/en-US/what-is-perseus.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ To our knowledge, the only other framework in the world right now that supports
6060

6161
## How fast is it?
6262

63-
[Benchmarks show](https://rawgit.com/krausest/js-framework-benchmark/master/webdriver-ts-results/table.html) that [Sycamore](https://sycamore-rs.netlify.app) is slightly faster than [Svelte](https://svelte.dev) in places, one of the fastest JS frameworks ever. Perseus uses it and [Actix Web](https://actix.rs), one of the fastest web servers in the world. Essentially, Perseus is built on the fastest tech and is itself made to be fast.
63+
[Benchmarks show](https://rawgit.com/krausest/js-framework-benchmark/master/webdriver-ts-results/table.html) that [Sycamore](https://sycamore-rs.netlify.app) is slightly faster than [Svelte](https://svelte.dev) in places, one of the fastest JS frameworks ever. Perseus uses it and [Actix Web](https://actix.rs) or [Warp](https://github.com/seanmonstar/warp) (either is supported), some of the fastest web servers in the world. Essentially, Perseus is built on the fastest tech and is itself made to be fast.
6464

6565
The speed of web frameworks is often measured by [Lighthouse](https://developers.google.com/web/tools/lighthouse) scores, which are scores out of 100 (higher is better) that measure a whole host of things, like *total blocking time*, *first contentful paint*, and *time to interactive*. These are then aggregated into a final score and grouped into three brackets: 0-49 (slow), 50-89 (medium), and 90-100 (fast). This website, which is built with Perseus, using [static exporting](:exporting) and [size optimizations](:deploying/size), consistently scores a 100 on desktop and above 90 for mobile. You can see this for yourself [here](https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Farctic-hen7.github.io%2Fperseus%2Fen-US%2F&tab=desktop) on Google's PageSpeed Insights tool.
6666

examples/basic/.perseus/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[package]
55
name = "perseus-engine"
6-
version = "0.3.0-beta.17"
6+
version = "0.3.0-beta.18"
77
edition = "2018"
88

99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

examples/basic/.perseus/builder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[package]
66
name = "perseus-engine-builder"
7-
version = "0.3.0-beta.17"
7+
version = "0.3.0-beta.18"
88
edition = "2018"
99
default-run = "perseus-builder"
1010

examples/basic/.perseus/server/Cargo.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,26 @@
33

44
[package]
55
name = "perseus-engine-server"
6-
version = "0.3.0-beta.17"
6+
version = "0.3.0-beta.18"
77
edition = "2018"
88

99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
1212
perseus = { path = "../../../../packages/perseus", features = [ "server-side" ] }
13-
perseus-actix-web = { path = "../../../../packages/perseus-actix-web" }
13+
perseus-actix-web = { path = "../../../../packages/perseus-actix-web", optional = true }
14+
perseus-warp = { path = "../../../../packages/perseus-warp", optional = true }
1415
perseus-engine = { path = "../" }
15-
actix-web = "3.3"
16+
actix-web = { version = "3.3", optional = true }
1617
futures = "0.3"
18+
warp = { version = "0.3", git = "https://github.com/arctic-hen7/warp", branch = "master", optional = true }
19+
# TODO Choose features here
20+
tokio = { version = "1", optional = true, features = [ "macros", "rt-multi-thread" ] } # We don't need this for Actix Web
21+
22+
# This binary can use any of the server integrations
23+
# Note: because of the way the CLI works, each feature must be an integration
24+
[features]
25+
integration-actix-web = [ "perseus-actix-web", "actix-web" ]
26+
integration-warp = [ "perseus-warp", "warp", "tokio" ]
27+
28+
default = [ "integration-warp" ]

0 commit comments

Comments
 (0)