Skip to content

Commit c16a494

Browse files
committed
Update build flow to bundle app
1 parent a06f887 commit c16a494

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

.github/workflows/build.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,34 @@ jobs:
4040
workspaces: engine
4141
key: ${{ matrix.platform.arch }}
4242

43+
# Setup Node & PNPM
44+
- name: Setup PNPM
45+
uses: pnpm/action-setup@v4
46+
with:
47+
run_install: false
48+
standalone: true
49+
package_json_file: web/package.json
50+
version: 8
51+
52+
- name: Setup Node
53+
uses: actions/setup-node@main
54+
with:
55+
node-version: 21
56+
cache: pnpm
57+
cache-dependency-path: 'web'
58+
4359
# Install cross
4460
- name: Install cross
4561
run: cargo install cross
4662

63+
- name: Install dependencies
64+
working-directory: web
65+
run: pnpm install
66+
67+
- name: Build web
68+
working-directory: web
69+
run: pnpm build
70+
4771
# Update version number in engine/Cargo.toml
4872
# If tag is a release use that
4973
# Otherwise use the version number in the engine/Cargo.toml and append it with -alpha

engine/src/routes/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::sync::Arc;
22

3+
use async_std::path::Path;
34
use auth::AuthApi;
45
use poem::{
5-
get, handler, listener::TcpListener, middleware::Cors, web::Html, EndpointExt, Route, Server,
6+
endpoint::StaticFilesEndpoint, get, handler, listener::TcpListener, middleware::Cors,
7+
web::Html, EndpointExt, Route, Server,
68
};
79
use poem_openapi::{OpenApi, OpenApiService, Tags};
810
use site::SiteApi;
@@ -43,10 +45,17 @@ pub async fn serve(state: AppState) {
4345
let api_service =
4446
OpenApiService::new(get_api(), "Hello World", "1.0").server("http://localhost:3000/api");
4547
let spec = api_service.spec_endpoint();
48+
49+
let frontend_dir = Path::new("www");
50+
let file_endpoint = StaticFilesEndpoint::new(frontend_dir)
51+
.index_file("index.html")
52+
.fallback_to_index();
53+
4654
let app = Route::new()
4755
.nest("/api", api_service)
4856
.nest("/openapi.json", spec)
4957
.at("/docs", get(get_openapi_docs))
58+
.at("/", file_endpoint)
5059
.with(Cors::new())
5160
.data(state);
5261

engine/www/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*
2+
!.gitignore

web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"scripts": {
1111
"dev": "vite",
12-
"build": "vite build",
12+
"build": "vite build && pnpm build:copy",
13+
"build:copy": "cp -r ./dist/* ../engine/www",
1314
"lint": "eslint -c .eslintrc.json --ext .ts,.tsx,.json ./src",
1415
"lint:fix": "echo Linting... && npm run lint -- --fix",
1516
"api-schema": "openapi-typescript http://localhost:3000/openapi.json -t -o ./src/api/schema.gen.ts"

0 commit comments

Comments
 (0)