-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcbabc0
commit 0e0f2f1
Showing
21 changed files
with
215 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[workspace] | ||
members = [ | ||
"packages/perseus", | ||
"packages/perseus-actix-web", | ||
"examples/showcase/app", | ||
"examples/showcase/server" | ||
"examples/showcase/server-actix-web" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
examples/showcase/server/Cargo.toml → ...ples/showcase/server-actix-web/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use perseus::config_manager::FsConfigManager; | ||
use perseus_actix_web::{configurer, Options}; | ||
use perseus_showcase_app::pages; | ||
use sycamore::SsrNode; | ||
use actix_web::{HttpServer, App}; | ||
|
||
#[actix_web::main] | ||
async fn main() -> std::io::Result<()> { | ||
HttpServer::new(|| { | ||
App::new() | ||
.configure( | ||
configurer( | ||
Options { | ||
index: "../app/index.html".to_string(), | ||
js_bundle: "../app/pkg/bundle.js".to_string(), | ||
wasm_bundle: "../app/pkg/perseus_showcase_app_bg.wasm".to_string(), | ||
templates_map: pages::get_templates_map::<SsrNode>() | ||
}, | ||
FsConfigManager::new() | ||
) | ||
) | ||
}) | ||
.bind(("localhost", 8080))? | ||
.run() | ||
.await | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "perseus-actix-web" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
perseus = { path = "../perseus" } | ||
actix-web = "3.3" | ||
actix-files = "0.5" | ||
urlencoding = "2.1" | ||
serde_json = "1" | ||
error-chain = "0.12" | ||
futures = "0.3" | ||
sycamore = { version = "0.5.1", features = ["ssr"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use actix_files::NamedFile; | ||
use actix_web::web; | ||
use sycamore::prelude::SsrNode; | ||
|
||
use perseus::{ | ||
config_manager::ConfigManager, | ||
serve::get_render_cfg, | ||
template::TemplateMap, | ||
}; | ||
|
||
use crate::page_data::page_data; | ||
|
||
/// The options for setting up the Actix Web integration. This should be literally constructed, as nothing is optional. | ||
#[derive(Clone)] | ||
pub struct Options { | ||
/// The location on the filesystem of your JavaScript bundle. | ||
pub js_bundle: String, | ||
/// The location on the filesystem of your WASM bundle. | ||
pub wasm_bundle: String, | ||
/// The location on the filesystem of your `index.html` file that includes the JS bundle. | ||
pub index: String, | ||
/// A `HashMap` of your app's templates by their paths. | ||
pub templates_map: TemplateMap<SsrNode> | ||
} | ||
|
||
async fn js_bundle(opts: web::Data<Options>) -> std::io::Result<NamedFile> { | ||
NamedFile::open(&opts.js_bundle) | ||
} | ||
async fn wasm_bundle(opts: web::Data<Options>) -> std::io::Result<NamedFile> { | ||
NamedFile::open(&opts.wasm_bundle) | ||
} | ||
async fn index(opts: web::Data<Options>) -> std::io::Result<NamedFile> { | ||
NamedFile::open(&opts.index) | ||
} | ||
|
||
/// Configures an existing Actix Web app for Perseus. This returns a function that does the configuring so it can take arguments. | ||
pub fn configurer<C: ConfigManager + 'static>(opts: Options, config_manager: C) -> impl Fn(&mut web::ServiceConfig) { | ||
move |cfg: &mut web::ServiceConfig| { | ||
cfg | ||
.data(get_render_cfg().expect("Couldn't get render configuration!")) | ||
.data(config_manager.clone()) | ||
.data(opts.clone()) | ||
// TODO chunk JS and WASM bundles | ||
// These allow getting the basic app code (not including the static data) | ||
// This contains everything in the spirit of a pseudo-SPA | ||
.route("/.perseus/bundle.js", web::get().to(js_bundle)) | ||
.route("/.perseus/bundle.wasm", web::get().to(wasm_bundle)) | ||
// This allows getting the static HTML/JSON of a page | ||
// We stream both together in a single JSON object so SSR works (otherwise we'd have request IDs and weird caching...) | ||
.route("/.perseus/page/{filename:.*}", web::get().to(page_data::<C>)) | ||
// For everything else, we'll serve the app shell directly | ||
// FIXME | ||
.route("*", web::get().to(index)); | ||
} | ||
} |
Oops, something went wrong.