mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-06-06 06:06:43 +00:00
static assets caching
This commit is contained in:
parent
98719670df
commit
f0254b3b77
12
.github/workflows/linux.yml
vendored
12
.github/workflows/linux.yml
vendored
@ -7,7 +7,6 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_and_test:
|
build_and_test:
|
||||||
strategy:
|
strategy:
|
||||||
@ -21,7 +20,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres
|
image: postgres
|
||||||
env:
|
env:
|
||||||
@ -80,7 +78,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
DATABASE_URL: postgres://postgres:password@localhost:5432/postgres
|
DATABASE_URL: postgres://postgres:password@localhost:5432/postgres
|
||||||
|
|
||||||
|
|
||||||
- name: tests
|
- name: tests
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
timeout-minutes: 40
|
timeout-minutes: 40
|
||||||
@ -90,7 +87,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
DATABASE_URL: postgres://postgres:password@localhost:5432/postgres
|
DATABASE_URL: postgres://postgres:password@localhost:5432/postgres
|
||||||
|
|
||||||
|
|
||||||
- name: Generate coverage file
|
- name: Generate coverage file
|
||||||
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
||||||
uses: actions-rs/tarpaulin@v0.1
|
uses: actions-rs/tarpaulin@v0.1
|
||||||
@ -102,8 +98,8 @@ jobs:
|
|||||||
# GIT_HASH is dummy value. I guess build.rs is skipped in tarpaulin
|
# GIT_HASH is dummy value. I guess build.rs is skipped in tarpaulin
|
||||||
# execution so this value is required for preventing meta tests from
|
# execution so this value is required for preventing meta tests from
|
||||||
# panicking
|
# panicking
|
||||||
GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61
|
GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61
|
||||||
OPEN_API_DOCS: 8e77345f1597e40c2e266cb4e6dee74888918a61
|
OPEN_API_DOCS: 8e77345f1597e40c2e266cb4e6dee74888918a61
|
||||||
CACHE_BUSTER_FILE_MAP: '{"map":{"./static/bundle/main.js":"./prod/bundle/main.1417115E59909BE0A01040A45A398ADB09D928DF89CCF038FA44B14850442096.js"},"base_dir":"./prod"}'
|
CACHE_BUSTER_FILE_MAP: '{"map":{"./static/bundle/main.js":"./prod/bundle/main.1417115E59909BE0A01040A45A398ADB09D928DF89CCF038FA44B14850442096.js"},"base_dir":"./prod"}'
|
||||||
|
|
||||||
- name: Upload to Codecov
|
- name: Upload to Codecov
|
||||||
@ -120,8 +116,8 @@ jobs:
|
|||||||
args: --no-deps --workspace --all-features
|
args: --no-deps --workspace --all-features
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: postgres://postgres:password@localhost:5432/postgres
|
DATABASE_URL: postgres://postgres:password@localhost:5432/postgres
|
||||||
GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value
|
GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value
|
||||||
OPEN_API_DOCS: 8e77345f1597e40c2e266cb4e6dee74888918a61
|
OPEN_API_DOCS: 8e77345f1597e40c2e266cb4e6dee74888918a61
|
||||||
|
|
||||||
- name: Deploy to GitHub Pages
|
- name: Deploy to GitHub Pages
|
||||||
if: matrix.version == 'stable' && (github.repository == 'mCaptcha/guard')
|
if: matrix.version == 'stable' && (github.repository == 'mCaptcha/guard')
|
||||||
|
@ -14,13 +14,14 @@
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use actix_web::body::Body;
|
use actix_web::body::Body;
|
||||||
use actix_web::{web, HttpResponse, Responder};
|
use actix_web::{http::header, web, HttpResponse, Responder};
|
||||||
use mime_guess::from_path;
|
use mime_guess::from_path;
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use crate::CACHE_AGE;
|
||||||
|
|
||||||
pub const DOCS: routes::Docs = routes::Docs::new();
|
pub const DOCS: routes::Docs = routes::Docs::new();
|
||||||
|
|
||||||
@ -62,6 +63,9 @@ pub fn handle_embedded_file(path: &str) -> HttpResponse {
|
|||||||
Cow::Owned(bytes) => bytes.into(),
|
Cow::Owned(bytes) => bytes.into(),
|
||||||
};
|
};
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
|
.set(header::CacheControl(vec![header::CacheDirective::MaxAge(
|
||||||
|
CACHE_AGE,
|
||||||
|
)]))
|
||||||
.content_type(from_path(path).first_or_octet_stream().as_ref())
|
.content_type(from_path(path).first_or_octet_stream().as_ref())
|
||||||
.body(body)
|
.body(body)
|
||||||
}
|
}
|
||||||
|
@ -61,9 +61,10 @@ pub static VERSION: &str = env!("CARGO_PKG_VERSION");
|
|||||||
pub static PKG_NAME: &str = env!("CARGO_PKG_NAME");
|
pub static PKG_NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
pub static PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
|
pub static PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
|
||||||
pub static PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");
|
pub static PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");
|
||||||
|
|
||||||
pub static VERIFICATION_PATH: &str = "mcaptchaVerificationChallenge.json";
|
pub static VERIFICATION_PATH: &str = "mcaptchaVerificationChallenge.json";
|
||||||
|
|
||||||
|
pub const CACHE_AGE: u32 = 365 * 24 * 3600;
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
|
@ -14,14 +14,15 @@
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use actix_web::body::Body;
|
use actix_web::body::Body;
|
||||||
use actix_web::{get, web, HttpResponse, Responder};
|
use actix_web::{get, http::header, web, HttpResponse, Responder};
|
||||||
use cache_buster::Files;
|
use cache_buster::Files;
|
||||||
use mime_guess::from_path;
|
use mime_guess::from_path;
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use crate::CACHE_AGE;
|
||||||
|
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
#[folder = "static/"]
|
#[folder = "static/"]
|
||||||
@ -34,7 +35,11 @@ pub fn handle_embedded_file(path: &str) -> HttpResponse {
|
|||||||
Cow::Borrowed(bytes) => bytes.into(),
|
Cow::Borrowed(bytes) => bytes.into(),
|
||||||
Cow::Owned(bytes) => bytes.into(),
|
Cow::Owned(bytes) => bytes.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
|
.set(header::CacheControl(vec![header::CacheDirective::MaxAge(
|
||||||
|
CACHE_AGE,
|
||||||
|
)]))
|
||||||
.content_type(from_path(path).first_or_octet_stream().as_ref())
|
.content_type(from_path(path).first_or_octet_stream().as_ref())
|
||||||
.body(body)
|
.body(body)
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
<. include!("../components/headers.html"); .> <. include!("./header/index.html");
|
<. include!("../components/headers.html"); .>
|
||||||
.>
|
<. include!("./header/index.html"); .>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<. include!("./taskbar/index.html"); .> <.
|
<. include!("./taskbar/index.html"); .>
|
||||||
include!("./help-banner/index.html"); .>
|
<. include!("./help-banner/index.html"); .>
|
||||||
<!-- Main content container -->
|
|
||||||
<div class="inner-container">
|
<div class="inner-container">
|
||||||
<!-- Main menu/ important actions roaster -->
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- end of container -->
|
|
||||||
</main>
|
</main>
|
||||||
<. include!("../components/footers.html"); .>
|
<. include!("../components/footers.html"); .>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user