Skip to content

Commit 1599765

Browse files
committed
2 parents 3ebd77f + 559932b commit 1599765

File tree

11 files changed

+91
-22
lines changed

11 files changed

+91
-22
lines changed

Cargo.lock

Lines changed: 65 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
members = [
44
"vercel_runtime",
5-
"examples/cron",
6-
"examples/nextjs",
7-
"examples/simple",
5+
"examples/*",
86
]
97

108
exclude = [
11-
"test/fixtures/01-include-files",
12-
"test/fixtures/02-with-utility",
13-
"test/fixtures/03-with-function",
14-
"test/fixtures/04-with-parameter",
15-
"test/fixtures/05-with-similar-entrypaths",
16-
"test/fixtures/06-with-toolchain-override"
9+
"test/*",
1710
]

examples/cron/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ serde_json = { version = "1.0.86", features = ["raw_value"] }
1313
serde_derive = "1.0.9"
1414
rand = "0.8.5"
1515
slack-morphism = { version = "1.2.2", features = ["hyper"] }
16-
vercel_runtime = "0.2.1"
17-
# vercel_runtime = { version = "0.2.1", path = "../../vercel_runtime" }
16+
url = "2.3.1"
17+
vercel_runtime = "0.3.4"
1818

1919
[[bin]]
2020
name = "cron"

examples/cron/api/cron.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use slack_morphism::{errors::SlackClientError, prelude::*};
2+
use std::collections::HashMap;
3+
use url::Url;
24
use vercel_runtime::{run, Body, Error, Request, Response, StatusCode};
35

46
#[derive(Debug, Clone)]
@@ -28,7 +30,18 @@ impl<T: SlackClientHttpConnector + Send + Sync> Lambda<'_, T> {
2830
self.slack.chat_post_message(&post_chat_req).await
2931
}
3032

31-
pub async fn handler(&self, _req: Request) -> Result<Response<Body>, Error> {
33+
pub async fn handler(&self, req: Request) -> Result<Response<Body>, Error> {
34+
let parsed_url = Url::parse(&req.uri().to_string()).unwrap();
35+
let hash_query: HashMap<String, String> = parsed_url.query_pairs().into_owned().collect();
36+
let secret = hash_query.get("secret").map(|x| &**x);
37+
38+
// https://vercel.com/docs/cron-jobs#how-to-secure-cron-jobs
39+
if secret != Some("geheim") {
40+
return Ok(Response::builder()
41+
.status(StatusCode::NOT_FOUND)
42+
.body(().into())?);
43+
}
44+
3245
let message = SlackMessage {};
3346

3447
self.post_message(&message, "#general").await?;

examples/cron/public/.gitkeep

Whitespace-only changes.

examples/cron/vercel.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
2+
"outputDirectory": "public",
23
"functions": {
34
"api/**/*.rs": {
45
"runtime": "vercel-rust@4.0.0-beta.3"
56
}
67
},
78
"crons": [
89
{
9-
"path": "/api/cron",
10+
"path": "/api/cron?secret=geheim",
1011
"schedule": "30 9 * * *"
1112
}
1213
]

examples/nextjs/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ serde_json = { version = "1.0.86", features = ["raw_value"] }
1313
serde_derive = "1.0.9"
1414
rand = "0.8.5"
1515
oorandom = "11.1.3"
16-
vercel_runtime = "0.2.1"
17-
# vercel_runtime = { version = "0.2.1", path = "../../vercel_runtime" }
16+
vercel_runtime = "0.3.4"
1817

1918
[[bin]]
2019
name = "rust"

examples/nextjs/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@
3030
"postcss": "^8.4.21",
3131
"tailwindcss": "^3.2.7",
3232
"tailwindcss-radix": "^2.8.0"
33+
},
34+
"engines": {
35+
"node": ">=16 <18"
3336
}
3437
}

examples/simple/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ serde_json = { version = "1.0.86", features = ["raw_value"] }
1212
serde_derive = "1.0.9"
1313
rand = "0.8.5"
1414
url = "2.3.1"
15-
vercel_runtime = "0.2.1"
16-
# vercel_runtime = { version = "0.2.1", path = "../../vercel_runtime" }
15+
vercel_runtime = "0.3.4"
1716

1817
[lib]
1918
path = "src-rs/lib.rs"

examples/simple/public/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)