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
Alewis/refactor routes #918
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
26eb615
Move Route struct into settings
ashleymichal 6bdca72
Get route from target from within publish_route fn
ashleymichal 580f7b6
Make routes a Vec<String> rather than HashMap
ashleymichal 2649300
Add 'routes' method to Target
ashleymichal acb0fcb
code review - extract failure case to early bail
ashleymichal 7996fb8
WIP
ashleymichal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interested in why this was a hashmap to begin with - i know we never used it anywhere but still interested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because technically routes are a map between a pattern and a script, and it is potentially useful within a Wrangler project if you wanted to "negate" a route by setting it to a
null
worker. For the purposes of this refactor, I am starting with the simplest implementation - a list of patterns - to reach parity with serverless.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense - will this bite us at all when we try to migrate? will the future require breaking changes to the toml? would like to avoid that as much as possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
predicting the future of routes is about as easy as predicting next year's weather (probably will be hotter than today, but who knows if it'll be raining). That being said, if it is clear before release that we need this data structure to change we can do that.