Skip to content

Commit ed2fedd

Browse files
committed
feat: add GitHub Actions workflow for CloudFlare deployment and update main function for error handling
1 parent 3025f32 commit ed2fedd

File tree

3 files changed

+83
-15
lines changed

3 files changed

+83
-15
lines changed

.github/workflows/deploy.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Deploy to CloudFlare Pages
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- '.github/workflows/pages.yml'
9+
- 'src/**.rs'
10+
- 'build.rs'
11+
- 'input.css'
12+
- 'package.json'
13+
- 'tailwind.config.js'
14+
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
jobs:
21+
build:
22+
runs-on: macos-15
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
submodules: "recursive"
29+
- uses: dtolnay/rust-toolchain@stable
30+
with:
31+
toolchain: nightly-2025-01-10
32+
target: wasm32-unknown-unknown
33+
34+
- uses: Swatinem/rust-cache@v2
35+
36+
- name: Pre Build
37+
run: |
38+
npm i
39+
- name: Build
40+
run: |
41+
cargo install --locked cargo-leptos
42+
cargo leptos serve -r
43+
- name: Upload artifact
44+
uses: actions/upload-artifact@v4
45+
with:
46+
path: ./dist
47+
48+
deploy:
49+
runs-on: ubuntu-latest
50+
needs: build
51+
steps:
52+
- uses: actions/download-artifact@v4
53+
- name: Deploy
54+
uses: cloudflare/wrangler-action@v3
55+
with:
56+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
57+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
58+
command: pages deploy ./artifact --project-name=homepage

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ ssr = [
3333
"leptos_meta/ssr",
3434
"leptos_router/ssr",
3535
]
36+
development = []
37+
38+
[target.aarch64-apple-darwin]
39+
rustflags = [ "-C", "link-arg=-fuse-ld=lld"]
3640

3741
# Defines a size-optimized profile for the WASM bundle in release mode
3842
[profile.wasm-release]

src/main.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

2020
static_route_generator.generate(&leptos_options).await;
2121

22-
let app = Router::new()
23-
.leptos_routes(&leptos_options, routes, {
24-
let leptos_options = leptos_options.clone();
25-
move || shell(leptos_options.clone())
26-
})
27-
.fallback(leptos_axum::file_and_error_handler(shell))
28-
.with_state(leptos_options);
22+
#[cfg(feature = "development")]
23+
{
24+
let app = Router::new()
25+
.leptos_routes(&leptos_options, routes, {
26+
let leptos_options = leptos_options.clone();
27+
move || shell(leptos_options.clone())
28+
})
29+
.fallback(leptos_axum::file_and_error_handler(shell))
30+
.with_state(leptos_options);
2931

30-
// run our app with hyper
31-
// `axum::Server` is a re-export of `hyper::Server`
32-
log!("listening on http://{}", &addr);
33-
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
34-
axum::serve(listener, app.into_make_service())
35-
.await
36-
.unwrap();
32+
// run our app with hyper
33+
// `axum::Server` is a re-export of `hyper::Server`
34+
log!("listening on http://{}", &addr);
35+
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
36+
axum::serve(listener, app.into_make_service())
37+
.await
38+
.unwrap();
39+
Ok(())
40+
}
41+
#[cfg(not(feature = "development"))]
42+
Ok(())
3743
}
3844

3945
#[cfg(not(feature = "ssr"))]

0 commit comments

Comments
 (0)