Skip to content

Commit

Permalink
chore: prevent leaking source code in examples (#90)
Browse files Browse the repository at this point in the history
* `4.0.0.beta.3`

* fix examples to not leak source code
  • Loading branch information
ecklf authored Mar 23, 2023
1 parent 543c337 commit 559932b
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 22 deletions.
70 changes: 65 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

members = [
"vercel_runtime",
"examples/cron",
"examples/nextjs",
"examples/simple",
"examples/*",
]

exclude = [
"test/fixtures/01-include-files",
"test/fixtures/02-with-utility",
"test/fixtures/03-with-function",
"test/fixtures/04-with-parameter",
"test/fixtures/05-with-similar-entrypaths",
"test/fixtures/06-with-toolchain-override"
"test/*",
]
4 changes: 2 additions & 2 deletions examples/cron/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ serde_json = { version = "1.0.86", features = ["raw_value"] }
serde_derive = "1.0.9"
rand = "0.8.5"
slack-morphism = { version = "1.2.2", features = ["hyper"] }
vercel_runtime = "0.2.1"
# vercel_runtime = { version = "0.2.1", path = "../../vercel_runtime" }
url = "2.3.1"
vercel_runtime = "0.3.4"

[[bin]]
name = "cron"
Expand Down
15 changes: 14 additions & 1 deletion examples/cron/api/cron.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use slack_morphism::{errors::SlackClientError, prelude::*};
use std::collections::HashMap;
use url::Url;
use vercel_runtime::{run, Body, Error, Request, Response, StatusCode};

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

pub async fn handler(&self, _req: Request) -> Result<Response<Body>, Error> {
pub async fn handler(&self, req: Request) -> Result<Response<Body>, Error> {
let parsed_url = Url::parse(&req.uri().to_string()).unwrap();
let hash_query: HashMap<String, String> = parsed_url.query_pairs().into_owned().collect();
let secret = hash_query.get("secret").map(|x| &**x);

// https://vercel.com/docs/cron-jobs#how-to-secure-cron-jobs
if secret != Some("geheim") {
return Ok(Response::builder()
.status(StatusCode::NOT_FOUND)
.body(().into())?);
}

let message = SlackMessage {};

self.post_message(&message, "#general").await?;
Expand Down
Empty file added examples/cron/public/.gitkeep
Empty file.
3 changes: 2 additions & 1 deletion examples/cron/vercel.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"outputDirectory": "public",
"functions": {
"api/**/*.rs": {
"runtime": "vercel-rust@4.0.0-beta.3"
}
},
"crons": [
{
"path": "/api/cron",
"path": "/api/cron?secret=geheim",
"schedule": "30 9 * * *"
}
]
Expand Down
3 changes: 1 addition & 2 deletions examples/nextjs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ serde_json = { version = "1.0.86", features = ["raw_value"] }
serde_derive = "1.0.9"
rand = "0.8.5"
oorandom = "11.1.3"
vercel_runtime = "0.2.1"
# vercel_runtime = { version = "0.2.1", path = "../../vercel_runtime" }
vercel_runtime = "0.3.4"

[[bin]]
name = "rust"
Expand Down
3 changes: 3 additions & 0 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"postcss": "^8.4.21",
"tailwindcss": "^3.2.7",
"tailwindcss-radix": "^2.8.0"
},
"engines": {
"node": ">=16 <18"
}
}
3 changes: 1 addition & 2 deletions examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ serde_json = { version = "1.0.86", features = ["raw_value"] }
serde_derive = "1.0.9"
rand = "0.8.5"
url = "2.3.1"
vercel_runtime = "0.2.1"
# vercel_runtime = { version = "0.2.1", path = "../../vercel_runtime" }
vercel_runtime = "0.3.4"

[lib]
path = "src-rs/lib.rs"
Expand Down
Empty file added examples/simple/public/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions examples/simple/vercel.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"outputDirectory": "public",
"functions": {
"api/**/*.rs": {
"runtime": "vercel-rust@4.0.0-beta.3"
Expand Down

0 comments on commit 559932b

Please sign in to comment.