diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0dbc836..e43a58f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,7 +8,6 @@ on: env: CARGO_TERM_COLOR: always - # DATABASE_URL: ${{ vars.DATABASE_URL }} jobs: build: diff --git a/.github/workflows/shuttle.yml b/.github/workflows/shuttle.yml new file mode 100644 index 0000000..d168c79 --- /dev/null +++ b/.github/workflows/shuttle.yml @@ -0,0 +1,38 @@ +name: Shuttle Deploy + +on: + push: + branches: [ "prod" ] + pull_request: + branches: [ "prod" ] + +jobs: + deploy: + runs-on: ubuntu-latest + environment: shuttle + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + cache-dependency-path: client/package-lock.json + + - name: Build front-end + run: | + npm ci + npm run deploy + working-directory: client + + - uses: shuttle-hq/deploy-action@main + with: + deploy-key: ${{ secrets.SHUTTLE_API_KEY }} + working-directory: "backend" + name: "my-project" + allow-dirty: "true" + no-test: "true" + cargo-shuttle-version: "0.28.1" + secrets: | + DB_PASSWORD = '${{ secrets.LOCAL_DB_PASSWORD }}' + COOKIE_KEY = '${{ secrets.COOKIE_KEY }}' \ No newline at end of file diff --git a/.github/workflows/ts.yml b/.github/workflows/ts.yml new file mode 100644 index 0000000..8fdf048 --- /dev/null +++ b/.github/workflows/ts.yml @@ -0,0 +1,26 @@ +name: TS CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + cache-dependency-path: client/package-lock.json + + - name: Build front-end + run: | + npm ci + npm run build + working-directory: client diff --git a/client/README.md b/client/README.md deleted file mode 100644 index e6cd94f..0000000 --- a/client/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Svelte + TS + Vite - -This template should help get you started developing with Svelte and TypeScript in Vite. - -## Recommended IDE Setup - -[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). - -## Need an official Svelte framework? - -Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. - -## Technical considerations - -**Why use this over SvelteKit?** - -- It brings its own routing solution which might not be preferable for some users. -- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app. - -This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project. - -Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate. - -**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?** - -Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information. - -**Why include `.vscode/extensions.json`?** - -Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project. - -**Why enable `allowJs` in the TS template?** - -While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant. - -**Why is HMR not preserving my local component state?** - -HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/rixo/svelte-hmr#svelte-hmr). - -If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR. - -```ts -// store.ts -// An extremely simple external store -import { writable } from 'svelte/store' -export default writable(0) -``` diff --git a/client/package.json b/client/package.json index 4d11bfe..fb7e535 100644 --- a/client/package.json +++ b/client/package.json @@ -5,6 +5,7 @@ "type": "module", "scripts": { "dev": "vite", + "deploy": "vite build --emptyOutDir --outDir ../server/public", "build": "vite build", "preview": "vite preview", "check": "svelte-check --tsconfig ./tsconfig.json" diff --git a/server/.gitignore b/server/.gitignore index a4e69a4..3231a10 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -2,4 +2,7 @@ target target/* .env -Secrets.toml \ No newline at end of file +Secrets.toml + +public +public/* \ No newline at end of file diff --git a/server/Cargo.lock b/server/Cargo.lock index 6d1bec1..15ecefa 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -1020,6 +1020,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a397c49fec283e3d6211adbe480be95aae5f304cfb923e9970e08956d5168a" + [[package]] name = "httparse" version = "1.8.0" @@ -1283,6 +1289,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2868,12 +2884,21 @@ checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" dependencies = [ "bitflags 2.5.0", "bytes", + "futures-util", "http 1.1.0", "http-body 1.0.0", "http-body-util", + "http-range-header", + "httpdate", + "mime", + "mime_guess", + "percent-encoding", "pin-project-lite", + "tokio", + "tokio-util", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -2993,6 +3018,15 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.15" diff --git a/server/Cargo.toml b/server/Cargo.toml index c0e2030..67824a3 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -23,4 +23,4 @@ shuttle-shared-db = { version = "0.44.0", features = ["postgres", "sqlx"] } sqlx = { version = "0.7.4", features = ["runtime-tokio", "postgres", "chrono", "macros", "tls-rustls"] } tokio = { version = "1.37.0", features = ["full"] } tower = "0.4.13" -tower-http = { version = "0.5.2", features = ["cors"] } +tower-http = { version = "0.5.2", features = ["fs", "cors"] } diff --git a/server/Shuttle.toml b/server/Shuttle.toml index 4371ec9..9a99efa 100644 --- a/server/Shuttle.toml +++ b/server/Shuttle.toml @@ -1 +1,5 @@ -name = "tijdcapsule" \ No newline at end of file +name = "tijdcapsule" + +assets = [ + "public/*" +] \ No newline at end of file diff --git a/server/src/routers/app.rs b/server/src/routers/app.rs index 9db0195..689f067 100644 --- a/server/src/routers/app.rs +++ b/server/src/routers/app.rs @@ -2,6 +2,7 @@ use axum::{http::Method, routing::{ get, post }, Router}; use tower_http::cors::{Any, CorsLayer}; use crate::utils::state::AppState; +use tower_http::services::ServeDir; use super::root; use super::capsule; @@ -16,7 +17,8 @@ pub fn new_with_state(state: AppState) -> Router { // let middleware = map_request_with_state(state.clone(), client_id::set_and_verify); Router::new() - .route("/", get(root::handler::get)) + .nest_service("/", ServeDir::new("public")) + .route("/health", get(root::handler::get)) .route("/capsule", post(capsule::handler::post)) .route("/capsule/:capsule_id", get(capsule::handler::get)) .layer(cors)