This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #918 from cloudflare/alewis/refactor-routes
Alewis/refactor routes
- Loading branch information
Showing
9 changed files
with
90 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use cloudflare::endpoints::workers::WorkersRoute; | ||
|
||
use crate::settings::target::target::Target; | ||
use crate::terminal::emoji; | ||
|
||
#[derive(Deserialize, PartialEq, Serialize)] | ||
pub struct Route { | ||
pub script: Option<String>, | ||
pub pattern: String, | ||
} | ||
|
||
impl From<&WorkersRoute> for Route { | ||
fn from(api_route: &WorkersRoute) -> Route { | ||
Route { | ||
script: api_route.script.clone(), | ||
pattern: api_route.pattern.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl Route { | ||
pub fn new(target: &Target) -> Result<Route, failure::Error> { | ||
if target | ||
.route | ||
.clone() | ||
.expect("You must provide a zone_id in your wrangler.toml before publishing!") | ||
.is_empty() | ||
{ | ||
failure::bail!("You must provide a zone_id in your wrangler.toml before publishing!"); | ||
} | ||
let msg_config_error = format!( | ||
"{} Your project config has an error, check your `wrangler.toml`: `route` must be provided.", | ||
emoji::WARN | ||
); | ||
Ok(Route { | ||
script: Some(target.name.to_string()), | ||
pattern: target.route.clone().expect(&msg_config_error), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters