Skip to content

Commit

Permalink
feat: add GitHub Actions workflow for CloudFlare deployment and updat…
Browse files Browse the repository at this point in the history
…e main function for error handling
  • Loading branch information
Phosphorus-M committed Jan 11, 2025
1 parent 3025f32 commit ed2fedd
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 15 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Deploy to CloudFlare Pages
on:
workflow_dispatch:
push:
branches:
- main
paths:
- '.github/workflows/pages.yml'
- 'src/**.rs'
- 'build.rs'
- 'input.css'
- 'package.json'
- 'tailwind.config.js'

permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: macos-15

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: "recursive"
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2025-01-10
target: wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v2

- name: Pre Build
run: |
npm i
- name: Build
run: |
cargo install --locked cargo-leptos
cargo leptos serve -r
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
path: ./dist

deploy:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/download-artifact@v4
- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy ./artifact --project-name=homepage
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ ssr = [
"leptos_meta/ssr",
"leptos_router/ssr",
]
development = []

[target.aarch64-apple-darwin]
rustflags = [ "-C", "link-arg=-fuse-ld=lld"]

# Defines a size-optimized profile for the WASM bundle in release mode
[profile.wasm-release]
Expand Down
36 changes: 21 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#[cfg(feature = "ssr")]
#[tokio::main]
async fn main() {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
use axum::Router;
use leptos::logging::log;
use leptos::prelude::*;
Expand All @@ -19,21 +19,27 @@ async fn main() {

static_route_generator.generate(&leptos_options).await;

let app = Router::new()
.leptos_routes(&leptos_options, routes, {
let leptos_options = leptos_options.clone();
move || shell(leptos_options.clone())
})
.fallback(leptos_axum::file_and_error_handler(shell))
.with_state(leptos_options);
#[cfg(feature = "development")]
{
let app = Router::new()
.leptos_routes(&leptos_options, routes, {
let leptos_options = leptos_options.clone();
move || shell(leptos_options.clone())
})
.fallback(leptos_axum::file_and_error_handler(shell))
.with_state(leptos_options);

// run our app with hyper
// `axum::Server` is a re-export of `hyper::Server`
log!("listening on http://{}", &addr);
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
// run our app with hyper
// `axum::Server` is a re-export of `hyper::Server`
log!("listening on http://{}", &addr);
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
Ok(())
}
#[cfg(not(feature = "development"))]
Ok(())
}

#[cfg(not(feature = "ssr"))]
Expand Down

0 comments on commit ed2fedd

Please sign in to comment.