Location-Based Next.js Middleware With New Relic Synthetics
Aug 15, 2023
Location-Based Next.js Middleware With New Relic Synthetics
If your app needs to behave differently based on user location, Next.js Middleware gives you control. And New Relic Synthetics make testing easy. Observability Week Day 3 features Daniel Kim! 00:00:00 - Welcome 00:00:31 - Who is Daniel Kim? 00:04:13 - How can I test location based app settings? 00:06:51 - What do you get back from a synthetic test? 00:12:53 - How is this about food? 00:16:43 - How should we start with synthetics? 00:22:32 - Adding in middleware 00:32:48 - Testing a button as if you’re in France 00:39:29 - Using Vercel 00:56:14 - Using imgx under the hood of Unsplash 01:04:41 - Using conditionals 01:19:23 - Digging into Vercel logs 01:23:49 - Where can people learn more about synthetics? Repo: https://github.com/lazyplatypus/food- … Demo: https://food-feuds-eight.vercel.app/ Linkshttps://twitter.com/learnwdaniel [6:52 AM]https://newrelic.com/ https://nextjs.org/docs/api-reference …https://www.bloomberg.com/news/articl …https://snack.tips/portland https://docs.newrelic.com/docs/synthe …https://twitter.com/learnwdaniel Watch future episodes live at https://twitch.tv/jlengstorf This episode was sponsored by: - Netlify (https://lwj.dev/netlify ) - Nx (https://lwj.dev/nx ) - Backlight (https://lwj.dev/backlight ) - Pluralsight (https://lwj.dev/pluralsight ) Live transcription by White Coat Captioning (https://whitecoatcaptioning.com/ ) Credits: Local Elevator by Kevin MacLeod is licensed under a Creative Commons Attribution license (https://creativecommons.org/licenses/ …) Source: http://incompetech.com/music/royalty- … Artist: http://incompetech.com/ Busybody by Audionautix is licensed under a Creative Commons Attribution license (https://creativecommons.org/licenses/ …) Artist: http://audionautix.com/ Additional sound effects obtained from https://www.zapsplat.com
Content
5.74 -> JASON: Hello, everyone.
7.31 -> Welcome to another episode of "Learn with
Jason."
10.55 -> Today on the show we have Daniel Kim.
13.04 -> Daniel, how are you?
14.33 -> DANIEL: I am doing fabulous.
16.03 -> How are you?
17.09 -> JASON: I am doing great.
18.83 -> A little bit of technical difficulties.
25.76 -> I'm excited to talk about the subject at hand
today, but first, before we dive into what
33.52 -> it is, let's talk a little bit about you.
35.719 -> Do you want to give us a bit of a background
on who you are and what you do?
40.17 -> DANIEL: My name is Daniel.
41.93 -> I work as a developer advocate at New Relic.
46.51 -> I actually came from an Next.js startup before
I joined New Relic.
51.26 -> I feel like I'm going back home with the stream.
55.36 -> I don't focus on browser or synthetics or
anything like that.
59.62 -> I focus on our Kubernetes experience and how
we support a cloud made for developers, but
65.121 -> today I get to jam out on frontend.
72.1 -> I love doing fun, weird projects.
74.6 -> That's my specialty.
76.45 -> I'm so excited to do a food based project
with you, Jason, because I love food.
83.57 -> That's why I live and work, is for food.
87.09 -> I'm very excited.
88.7 -> JASON: Very much agreed.
92.47 -> People are like, why do you travel?
93.759 -> I only go to cities where the food is good.
96.12 -> DANIEL: Yeah, I want to try every kind of
barbecue, every kind of dumpling.
102.549 -> That's why I like to travel.
104.16 -> Yeah, for sure.
105.42 -> JASON: I have publicly stated that I would
happily become a dumptarian if I could.
110.57 -> DANIEL: Yesterday, I hosted a meetup in San
Francisco called devs and dumps where we ordered
118.63 -> 1,000 dumplings.
119.63 -> JASON: What?
120.63 -> DANIEL: It was like 80% gone in a couple of
hours.
124.99 -> It was amazing the rate at which dumplings
were consumed at that meetup.
129.95 -> I was like we ordered way too much food, because
we had trays and trays and trays of dumplings.
136.29 -> Most of it was gone by the end of the night.
140.51 -> JASON: I had a dream where I was surrounded
by trays and trays of dumplings.
145.68 -> I feel like you may have put to go one of
my fantasies actually.
150.67 -> (Laughter)
152.06 -> DANIEL: Yeah, it was a fantasy of mine for
sure because it's always been a dream of mine
158.29 -> to be surrounded, all 360 degrees, with dumplings
and every different type of dumpling.
164.23 -> JASON: I'm looking for a studio G bleed of
leaning of towers of dumplings all around
172.58 -> me.
175.29 -> We could talk about this all day, but we should
probably talk about something else.
181.5 -> DANIEL: Sorry.
182.5 -> I get real passionate about food.
187.4 -> It's a major driver for me.
189.72 -> JASON: Speaking of which, let's talk a little
bit about what we're going to do today.
196.27 -> Okay.
199.29 -> Stick with us, chat, because it is going to
take us a second to get to why this is about
202.08 -> food.
204.26 -> We're going to be working today with Next.js.
207.15 -> More specifically, we want to start playing
with the ways Next.js can handle location
214.84 -> based stuff.
220.71 -> There's a lot of cool stuff in this middleware
where you can determine where somebody is
224.97 -> requesting the site from and make alterations
to what the site does.
230.15 -> You can also redirect them to different versions
of the page, but what's really interesting
235.069 -> about it is it poses some challenge that I
never had to think about before, such as when
243.379 -> I have said that everybody in, I don't know,
Denver, Colorado, needs to see a different
250.87 -> version of a site, how do I verify that it's
working, right?
256.22 -> Because I'm in Portland.
259.259 -> If I'm attempting to troll my friends, I can
like set the location to Portland and then
264.15 -> see that it works, but I don't have time to
go to Denver and load the sightly site and
269.501 -> make sure it works.
270.62 -> If I was targeting multiple locations, what
do I do to solve that?
275.1 -> It sounds like you have a potential solution
for us today.
279.38 -> DANIEL: For the first time, enterprise software
has a solution for us regular developers.
286.38 -> (Laughter)
287.97 -> DANIEL: That should be a sound bite.
291.41 -> JASON: Chris, you know what to do.
294.4 -> Chris is the editor for the show.
297.44 -> DANIEL: Synthetic monitoring as a concept
has been around for quite a while actually.
303.009 -> It's a way mostly back end developers test
their operation systems are working efficiently.
310.65 -> Now synthetic monitoring can be used for frontend
websites.
314.819 -> It can automatically send a robot or script
to your website from any location you can
321.389 -> dream of or you can spin up a location of
your own.
325.04 -> You can theoretically set one up from Antarctica,
if you wanted.
327.55 -> JASON: Okay.
328.55 -> DANIEL: You can have a script test your website
or system as if it was a real life person
336.65 -> or a machine from a particular location.
339.73 -> You could actually have a script from Denver,
Colorado, try out the workflow from your entire
347.26 -> website, like clicking around and validating
that some things work and is displaying what
353.09 -> you want it to display.
354.93 -> You don't have to physically travel to Denver,
Colorado, to test if your website works.
359.55 -> JASON: That's great because the horse at that
airport freaks me out.
363.819 -> DANIEL: Oh, yeah.
365.77 -> That airport has a lot of conspiracy theories
around it.
368.9 -> JASON: Chat, if you've never gone down the
rabbit hole of DIA conspiracy theories, you
376.32 -> should definitely do it because it's weird.
379.43 -> It's dark.
380.49 -> It's amazing.
382.27 -> There's a demon horse.
383.44 -> (Laughter)
384.44 -> DANIEL: Yeah, I've only been there once.
388.72 -> I try not to connect to Denver anymore.
391.18 -> (Laughter)
392.18 -> JASON: I imagine that was the exact opposite
impact they were trying to have when they
398.85 -> built that airport.
403.72 -> If I'm building an app and that app relies
on location, if I want to test that app from
410.31 -> any location to validate what I'm building
works, a synthetic is going to allow me to
420.09 -> have a robot actually hit the site and then
it gives me what do I get when I do that?
426.34 -> Do I get the response headers?
430.72 -> Do I get a screenshot?
433.99 -> What's my goody bag look like after I've run
a synthetic?
436.889 -> DANIEL: You get a bunch of goody bags.
439.5 -> You get a screenshot.
442.08 -> You get the entire graph of how things load.
447.54 -> This is actually really important for more
complex websites that might be loading different
452.63 -> resources based on your location and CDN.
455.14 -> If they use a CDN that's region based like
a developer from Japan goes to your website
465.46 -> from a different CDN, you can see the different
performance issues that may come from multiple
474.099 -> people at multiple locations accessing your
website.
477.65 -> JASON: Yeah.
479.79 -> I'm just kind of thinking how useful that
waterfall would be to see it from different
485.5 -> places because one of the big challenges when
you're building a site is, especially as it
491.33 -> gets more complex let's say you've got your
frontend on the CDN and that's globally hosted
499.349 -> and you're happy.
500.349 -> Then you reach for a service like AWS lambda,
without thinking about it, you only locate
506.349 -> those lambdas in U.S. east 2.
516.709 -> When you load the site from Australia, you
start 20 to feel that lag of the speed of
521.94 -> light from the east coast of Australia to
the U.S.
529.26 -> We forgot to add locations for where our back
services run.
539.73 -> You can start to find these bottlenecks that
you wouldn't notice if you're building for
544.85 -> your own speed because I'm here in Portland.
546.95 -> If I put something on west coast U.S., I'm
not going to notice.
549.22 -> It's going to be really snappy.
550.35 -> I'm going to be super impressed with myself,
but somebody loading that from Asia is going
556.08 -> to be like, why is this website so slow?
558.86 -> My CDN node is Hong Kong.
561.87 -> Why the heck is this so dang slow?
565.5 -> The synthetics give a really good indication
of, oh, wait, I have a huge lag between this
570.35 -> request and the response from my API.
573.37 -> DANIEL: That's for sure.
575.19 -> And the best part is when these issues happen,
you want to get in front of it as soon as
580.71 -> possible.
582.85 -> With a platform like New Relic, you can basically
get alerted when certain things are not what
587.39 -> you want them to be.
588.39 -> If you get a Slack notification or an email
about this is not going well so you can go
595.82 -> fix it, more of your customers and user notice.
598.9 -> That's the power of setting this up for your
large enterprise production website.
605.93 -> You want to make sure that things are working
as much as possible to keep your uptime up.
611.029 -> JASON: Yeah.
612.029 -> DANIEL: At the New Relic, internally we use
inset synthetics to drive our internal emergency
617.75 -> room.
618.95 -> We have a synthetic testing our login flow
to make sure every one of our users throughout
625.74 -> the world is able to access our website.
628.25 -> If that synthetic fails for any of our locations,
the team gets paid to be like, yo, this login
633.85 -> doesn't work for your users.
637.029 -> JASON: You just said something that made me
connect a dot.
641.639 -> I had thought when you said we could use synthetics,
that it was a page load, but you just said
648.1 -> you test the login flow.
649.51 -> I can run like a full integration suite from
anywhere in the world using synthetics?
654.12 -> DANIEL: Yeah.
655.62 -> JASON: Oh.
657.12 -> DANIEL: I don't know.
659.94 -> Angie is the queen of Seleniums.
662.51 -> You can run browser tests with synthetics.
668.769 -> You can test those really complex workflows
directly from Dallas, Texas, or Portland or
677.5 -> Tokyo.
678.5 -> JASON: That feels especially important as
you start getting into things like, for example,
684.56 -> GDPR compliance.
685.79 -> You want to run different things in different
places.
689.19 -> The worst experience is when you start getting
notices about legal policies that don't apply
694.12 -> to you.
696.42 -> You just dismiss it because you don't care.
701.24 -> Instead, we want people to actually see relevant
things that affect them.
705.51 -> If you don't have a way to test that, it can
lead to the engineers just saying, well, I
710.81 -> don't know, better safe than sorry, just show
it to everybody.
713.69 -> I think that's not really what we're after,
right?
717.23 -> Also, being able to use an integration test
to show the flow of, oh, yes, our payment
723.6 -> parity scripting actually works.
726.389 -> When you load from a country with a lower
income, you reduce the price of your product
733.649 -> to match the income level so it is affordable.
736.94 -> Purchasing power parity is what it's called.
739.52 -> I love that stuff, but it's really hard to
test, so a lot of us use somebody else's script
745.44 -> and ship and hope for the best.
748.01 -> Being able to actually put together an integration
flow and hit the site from somewhere you know
752.93 -> has a price change and make sure the price
actually changed and when you go through the
757.91 -> checkout, you see it works, all that stuff
is really important and really hard to set
763.899 -> up if you don't have something like synthetics.
769.62 -> Okay.
771.15 -> Let's take this full circle here.
773.69 -> How is this about food?
774.959 -> DANIEL: Oh, yeah.
776.79 -> I think there's lots of famous bites that
you can have with your friends.
781.459 -> One of the most divisive things you can do
is starting an argument about the purity or
787.81 -> the ultimate way to cook anything.
790.66 -> I know there's a famous feud on this channel
about burgers.
795.47 -> What is the actual best way to cook burgers?
798.41 -> JASON: Yes.
800.529 -> Yes.
801.579 -> There is a checkered past.
805.44 -> Sarah Drasner, who is one of my favorite people
in the world and also one of the best devs
814.04 -> I've ever met, has the unbelievably incorrect
opinion that the best way to make a burger
820.52 -> is to sous vide the burger patty.
823.99 -> I don't know how anybody could look at a Smashburger
and go, I'm going to put this burger in the
831.16 -> bath and this will be better.
833.69 -> DANIEL: Food fights.
836.81 -> We want to keep everybody happy.
841.16 -> When Sarah visits the website from her location,
we want to keep her keep the friendship alive.
849.34 -> JASON: Yes.
850.34 -> (Laughter)
851.34 -> DANIEL: We want to make sure the website says
the best way to cook burgers is sous vide
857.509 -> burgers, but we also want to keep Jason happy.
860.99 -> Because he's from Portland, we want it to
say Smashburger.
868.949 -> That's the theme of today's stream.
871.82 -> How do we keep friendships together by keeping
everyone happy by making them feel their favorite
880.88 -> cooking style is X?
883.579 -> JASON: The underlying message of today's show
is we're going to teach you how to make websites
890.35 -> that sucks up to them and makes them think
they're correct.
893.81 -> DANIEL: Exactly.
894.93 -> That's marketing.
895.97 -> (Laughter)
896.97 -> DANIEL: That should be another sound bite
too.
904.97 -> That's marketing.
906.97 -> (Laughter)
907.97 -> JASON: Okay.
909.98 -> I think at this point maybe the best thing
to do is to switch over and see how all this
914.579 -> works, so why don't we head over into our
pair programming view?
919.56 -> I'm going to get this off screen.
922.079 -> We're going to make where did my window go?
925.49 -> Here it is.
926.85 -> First and foremost, this episode, like every
episode, is being live captioned.
931.269 -> You have a closed caption button there on
your Twitch player so you can turn that on.
941.94 -> Tess is here from White Coat Captioning, taking
down all these words.
944.899 -> Thank you so much for being here, Tess.
947.52 -> That is made possible through the support
of our sponsors: Netlify, Nx, Pluralsight,
951.569 -> and New Relic, who is putting on this whole
collection of O11y Week streams.
958.08 -> I don't know why I forgot the word for stream.
964.87 -> We're talking today to Daniel.
968.399 -> If you want to go and follow Daniel, you can
do so on the Twitters.
974.35 -> I'll drop this link in here.
976.14 -> DANIEL: I might have slightly gotten inspired
by Jason from my Twitter handle.
981.029 -> JASON: Learn with Daniel.
982.88 -> I love it.
983.88 -> All right.
984.88 -> We're talking about New Relic today.
987.13 -> We are going to get into the New Relic here's
a link to the home page if you want to check
992.79 -> that out.
993.79 -> We'll get into the synthetics and the docs
and stuff as we go.
999.72 -> I think that's the extent of my knowledge
on what we're doing today.
1003.31 -> Daniel, what should we do first?
1005.63 -> DANIEL: Yeah.
1007.139 -> So, I already started a base repo for us to
work from.
1012.56 -> It's under GitHub.com/ let me drop the link
instead of me trying to stumble through a
1021.259 -> large URL.
1022.259 -> JASON: All right.
1023.839 -> I've got that here.
1026.31 -> DANIEL: Let's just clone that repo.
1031 -> JASON: I'm going to clone down the starter.
1034.03 -> DANIEL: Uh huh.
1035.589 -> JASON: Okay.
1036.63 -> Let me grab this.
1037.709 -> DANIEL: Feel free to follow along, folks at
home.
1041.1 -> JASON: This should be a good time.
1042.95 -> We're using the GitHub CLI here.
1044.81 -> Then I'm going to check out starter.
1049.46 -> Come on.
1055.56 -> Get branch.
1061.67 -> Hit fetch all.
1066.82 -> Now we can get starter.
1071.909 -> Please stop helping.
1074.93 -> That is not a helpful thing to happen when
I tell you to do this thing.
1081.13 -> How do I get the starter branch if I'm what
is the thing I'm doing wrong here?
1091.789 -> DANIEL: I use GitHub.
1094.36 -> I'm an embarrassment.
1098.71 -> JASON: There's a way to do this.
1105.309 -> Maybe I need to do a get checkout origin.
1109.289 -> DANIEL: You can also do dash B.
1116.32 -> JASON: But I'm in the wrong branch is the
problem.
1119.159 -> I'm not in the correct folder.
1122.38 -> Oh, my God.
1123.919 -> My goodness, y'all.
1125.45 -> We're off to a great start.
1127.49 -> DANIEL: I'll say Git is the hardest part.
1131.07 -> JASON: That's true.
1133.559 -> It's all downhill from here, everybody.
1135.75 -> Okay.
1136.75 -> We're going to open up this project.
1140.669 -> I'll start by installing dependencies.
1144.57 -> Thank you.
1147.43 -> DANIEL: Is that
a monkey emoji?
1157.48 -> (Laughter)
1158.48 -> JASON: Let's start this thing up and see what
we've got.
1159.77 -> I'm going to run npm run dev.
1165.15 -> And we've got site is at local host 3,000.
1168.6 -> I'll copy this, come over here, and here is
our site.
1175.919 -> This is the burger brawl.
1177.8 -> We've got smash burgers versus sous vide burgers.
1182.309 -> I think this is the best website that's ever
been made.
1186.89 -> DANIEL: I don't know because it's basically
saying we've got to figure out who the winner
1193.09 -> is though.
1194.09 -> It's not complete.
1195.09 -> This is a start to a great website.
1197.29 -> JASON: It is the seed of a perfect website.
1201.22 -> (Laughter)
1202.419 -> DANIEL: Nice.
1204.82 -> Yeah, let's just start by making a page talking
about the actual correct answer, which is
1215.549 -> smash burgers.
1216.549 -> I think we should just start by making a new
page.
1219.429 -> JASON: Okay.
1220.7 -> We'll say answer.txs.
1222.58 -> I'll copy and paste some things so we don't
have to remember it all.
1233.87 -> Let's see.
1234.87 -> How does this all work?
1236.24 -> We've got the contenders' component here.
1239.03 -> We'll say "the best burger
1245.789 -> DANIEL: Smashburger.
1252.45 -> JASON: Okay.
1259.13 -> And if we just drop this out, that should
give us a pretty let's go take a look at what
1266.27 -> I've done.
1270.06 -> Cool.
1273.61 -> I'm pretty happy with that.
1274.61 -> That seems okay.
1275.61 -> What am I missing?
1276.61 -> DANIEL: That was so fast.
1277.65 -> Yes, that looks beautiful.
1279.52 -> JASON: I think this is the magic of component
based frontends.
1284.14 -> Oh, good.
1286.32 -> I can just read what this is.
1288.49 -> That's what I want.
1289.49 -> Yes, perfect.
1290.49 -> I am done.
1291.539 -> DANIEL: We've also got to add an answer for
the wrong answer because I'm also on Team
1297.11 -> Jason.
1298.11 -> I love Smashburger.
1300.669 -> We can call the other page.
1302.7 -> I don't know what we should call it.
1304.38 -> JASON: The wrong.
1305.95 -> DANIEL: Nice.
1307 -> JASON: Then we'll go in here and swap this
one out, and we'll say then we can switch
1325.88 -> over to wrong.
1328.23 -> DANIEL: You do you, I guess.
1333.7 -> (Laughter)
1334.7 -> DANIEL: Sorry.
1336.4 -> This like cracks me up.
1338.25 -> I can't believe I'm coding this live on a
stream on like a work stream.
1342.76 -> This is really fun.
1344.299 -> JASON: Yeah.
1345.299 -> Sometimes I do just take a moment to think
about what I do for a living.
1349.27 -> You've just got to chuckle.
1351.21 -> DANIEL: Yeah, it's really funny.
1357.12 -> I think that took all of three minutes.
1359.92 -> We've now got to put in some middleware logic.
1362.25 -> JASON: Okay.
1363.77 -> DANIEL: A middleware logic to redirect the
request as it comes in to the correct page.
1373.309 -> JASON: Okay.
1374.59 -> DANIEL: So, I think let's just start with
VS code and going and creating a new file
1382.74 -> in the root directory called middleware.ts.
1384.919 -> I think this is a really good time to bring
up the next documentation, which I think is
1393.779 -> fabulous.
1394.779 -> I'm going to drop that in the chat.
1396.95 -> JASON: Oh, you you went straight to the server.
1405.22 -> Is it this one?
1406.91 -> DANIEL: Yeah, that one.
1408.529 -> JASON: Okay.
1409.529 -> DANIEL: We're going to be using next/server
to basically help us with middleware.
1416.95 -> We can actually get metadata about the requests
coming in and use the next dash server to
1423.419 -> redirect all the traffic coming in to the
right page.
1426.929 -> JASON: Uh huh.
1428.059 -> DANIEL: We're going to be importing the type
next request from next server as well as next
1435.64 -> response.
1436.64 -> JASON: Daniel, I'm going to interrupt you
real quick because momen88 the assayed, we
1444.179 -> want other options different than burgers
if this is about food, and I think that is
1449.31 -> brilliant.
1450.47 -> Chat, here's your challenge.
1454.02 -> Let us know in the chat what the best food
feuds are.
1458.12 -> New York versus Chicago style pizza.
1461.309 -> Include where they're from because if we have
more time, we can add more locations and answers
1468.779 -> and options for things.
1471.46 -> If you load this site from New York or Chicago,
we can show pizza instead of burgers, for
1479.82 -> example.
1480.82 -> Drop those into the chat.
1482.14 -> If we've got time, we'll come back and do
some.
1484.38 -> All right.
1485.38 -> Sorry, Daniel.
1486.38 -> I interrupted you.
1487.38 -> Go ahead.
1488.38 -> DANIEL: I just want to drop this in the link
to people everything you can do with next
1495.69 -> server.
1496.69 -> In the server, we're going to import from
next/server as well as import next response
1508.58 -> from next/server.
1509.6 -> JASON: As not a type, right?
1512.42 -> DANIEL: That is not a type.
1514.07 -> JASON: Okay.
1515.07 -> We're going to get import
1517.33 -> DANIEL: I love how next just abstracts this
out for you so you don't have to do anything.
1524.95 -> That is just beautiful.
1526.75 -> And then we want to export a function called
middleware.
1533.049 -> And then the input would be the request.
1536.27 -> We have to do req, and then we do the little
colon and then next request.
1544.17 -> JASON: Okay.
1546.24 -> Is that the only argument?
1547.73 -> DANIEL: Yeah, because that's we're basically
looking at the request coming into the website
1552.91 -> and figuring out where to direct it after
that.
1555.409 -> JASON: Got it.
1556.63 -> Got it.
1557.99 -> DANIEL: Let's make an if statement.
1563.37 -> To make it easier, what country do you think
would prefer sous vide burgers over smash
1568.82 -> burgers?
1569.82 -> JASON: Let's say France because they invented
the wait, did France invent Sous vide?
1579.49 -> You know what?
1580.49 -> I'm sticking to my guns.
1582.21 -> You heard it here first.
1584.429 -> DANIEL: I'm afraid of pissing off people,
but I also like living on the edge.
1591.88 -> I like it.
1595.11 -> (Laughter)
1598.01 -> DANIEL: Let's see.
1602 -> If direct dot geo dot country equals FR
1612.24 -> JASON: It's a country code, right, capital
FR?
1618.69 -> DANIEL: Yeah, exactly.
1620.62 -> Then req dot next URL dot path name equals
wrong.
1638.58 -> Else we can do req next URL path name equals
what was the URL name?
1649.03 -> I forgot.
1650.36 -> JASON: Answer.
1651.69 -> DANIEL: Answer, yes.
1653.68 -> JASON: And now
1654.93 -> DANIEL: Oh, sorry.
1656.57 -> Go ahead.
1657.66 -> JASON: How does this work?
1660.83 -> If I remember correctly how next middleware
works, because we put this in the root, it
1664.549 -> is going to run on every request, right?
1667.97 -> DANIEL: Uh huh.
1669.919 -> JASON: If I'm reading this code correctly,
somebody from France would never be able to
1676.08 -> get to the home page.
1677.08 -> They would automatically see the sous vide.
1681.029 -> Somebody from anywhere else would automatically
see smash burgers the way this code is written
1685.13 -> right now.
1686.13 -> Is that correct?
1687.13 -> DANIEL: Yes.
1688.27 -> JASON: Okay.
1689.88 -> Do we want to test that first?
1690.96 -> DANIEL: We can't test that right now because
we have to return something in this function.
1696.45 -> JASON: Got it.
1697.45 -> Okay.
1698.45 -> DANIEL: Let's do return next response dot
rewrite and then parentheses req that next
1712.95 -> URL.
1716.32 -> Right now, what it should do is redirect directly
to the sous vide, the wrong page or the answer
1723.74 -> page, depending on where you're from.
1726.09 -> Hopefully it does that.
1728.01 -> That would be great.
1729.97 -> JASON: Let's see.
1732.6 -> It didn't like oh, that's fine.
1734.59 -> That's because we didn't set a key prop.
1738.7 -> Middleware is running.
1740.22 -> Did something fail?
1744.29 -> Unexpected token.
1746.25 -> Oh, interesting.
1748.779 -> DANIEL: Oh, I forgot.
1752.05 -> JASON: We're redirecting everything.
1755.37 -> This is catching the JavaScript files and
all the assets as well, so we're returning
1760.2 -> okay, okay.
1761.53 -> DANIEL: I forgot to do something.
1763.58 -> We forgot to export the URL variable.
1769.24 -> If we don't export that variable, it'll ruin
everything.
1773.6 -> We have to limit what we redirect.
1777.559 -> What we want to do is we want to export the
constant called config.
1781.159 -> JASON: From the middleware?
1787.78 -> DANIEL: Yeah.
1792.59 -> And then we want to do matcher colon and then
quote marks and the slash.
1799.19 -> We basically want to redirect every request
to the main page to answer or wrong.
1806.029 -> Hopefully that worked.
1807.72 -> JASON: There we go.
1809.99 -> There we go.
1811.13 -> DANIEL: Life coding gets my blood pumping.
1814.929 -> JASON: All right.
1817.13 -> DANIEL: But we want it to be a little bit
more dramatic because we want people to go
1820.95 -> to the home page and click a button to find
out the right answer.
1826.59 -> Let's now put that.
1828.11 -> In the main page, let's add a button that
says "find out the right answer" or "find
1834.21 -> out the answer."
1835.21 -> I don't know what the right phrasing would
be, but having a button for that would be
1838.4 -> cool.
1839.4 -> JASON: We have a component for that, which
is cool.
1842.289 -> We can go here.
1843.289 -> DANIEL: I don't know how that happened.
1844.36 -> JASON: It's almost like we planned this.
1848.25 -> Let's go to the big link here.
1852.929 -> We want the H ref.
1857.38 -> What do we do here?
1860.039 -> Where do we link to?
1861.71 -> DANIEL: Yeah.
1863.159 -> The best part is you can make any URL because
basically we can have the middleware redirect
1868.139 -> the URL you create here to some other thing.
1871.83 -> But for the sake of this, we can just make
it let's just have the default be "go to answer."
1878.52 -> JASON: Okay.
1881.059 -> DANIEL: And then in the middleware, we can
say, if it is from France
1889.139 -> JASON: From Frawns?
1892.11 -> DANIEL: Sorry.
1896.61 -> (Laughter)
1898.86 -> JASON: Okay.
1903.36 -> Now we have a button, but we can't see it
just yet, so we need to do I just change this
1909.88 -> to answer and now it will work?
1913.039 -> DANIEL: Yeah.
1914.549 -> JASON: Yeah, yeah.
1916.809 -> Okay.
1917.809 -> Look at that.
1919.08 -> Okay.
1920.13 -> Moment of truth.
1921.34 -> DANIEL: Please work.
1922.76 -> Yes!
1923.76 -> JASON: Just whacked my ceiling.
1927.41 -> Okay.
1929.95 -> I think we did the thing because I don't know
how to test this because I'm not in France.
1936.19 -> DANIEL: Honestly, I would love to get a work
trip expense to do to France to test this
1942.57 -> website.
1943.57 -> Hey, boss.
1944.57 -> I need to go to France to test this website.
1947.549 -> I would love to be a software engineer where
synthetics exist.
1952.019 -> That would be so nice.
1955.169 -> JASON: We just got such a better button text
from the chat.
1960.409 -> DANIEL: Discover the truth.
1962.82 -> JASON: Discover the truth.
1964.87 -> I love it.
1966.08 -> I love it.
1967.37 -> DANIEL: Now, let's just test the button as
if we were in France.
1973.26 -> Are you down?
1974.94 -> JASON: Yes.
1976.06 -> I'm down.
1977.18 -> Let's do it.
1978.18 -> DANIEL: You can go to New Relic.
1980.19 -> The best part is there's no coding required
for this.
1984.769 -> You can have coding.
1986.679 -> I prefer not to code if I don't have to.
1991.179 -> All we have to do is go into oh, maybe not
upgrade yet.
1995.95 -> This is called marketing, folks.
1999.019 -> There's an X on the top.
2000.019 -> JASON: Oh, there it is.
2001.019 -> DANIEL: You have to go to synthetics.
2005.059 -> It's in the very bottom of the little robot.
2007.039 -> Perfect.
2008.039 -> JASON: I like this little robot.
2010.22 -> Just zoom in on that robot for a minute.
2012.3 -> It's a good robot.
2013.3 -> All right.
2014.539 -> DANIEL: Then create your first monitor.
2016.679 -> There's that big white button.
2020.4 -> And then today we're going to be doing something
really basic, but you can go as complex as
2027.1 -> you want.
2028.1 -> Like I said before, you can create very long
selenium tests to test your very complex environment.
2033.99 -> Today, we have a button that we have to click
to show a page.
2037.139 -> We're not dealing with rocket science here.
2038.899 -> JASON: True.
2039.899 -> DANIEL: So, we're going to do a user step
execution, the zero code monitor building
2046.139 -> on the bottom right.
2047.75 -> JASON: Okay.
2049.35 -> DANIEL: And we have to create a name.
2051.8 -> What should be the name?
2052.99 -> JASON: The food feud.
2059.889 -> Here's actually a question.
2062.02 -> Am I setting up one named synthetic for each
task or am I creating a group of synthetics
2072.63 -> and I can add checks underneath this?
2075.89 -> DANIEL: It depends on how you want to set
it up.
2085.6 -> You can be very lazy.
2088.38 -> France could fail.
2090.05 -> If we assert the answer should always be sous
vide burgers, you could go that way.
2095.649 -> If you have a large environment, I suggest
you have a different synthetic for every single
2102.87 -> scenario you expect.
2105.67 -> You should have a separate synthetic for France.
2109.15 -> You can always validate for users of France
it will always show the best burger is sous
2116.56 -> vide burgers and then other places would have
Smashburger.
2129.9 -> JASON: We can do the FR so I know that we're
checking France.
2138.54 -> DANIEL: Exactly.
2139.78 -> JASON: Okay.
2141.02 -> DANIEL: If you could change the period to
one minute, that would be great.
2145.24 -> JASON: Just so that we get more of these.
2150.09 -> Do I need to care about any of these?
2152.64 -> DANIEL: No.
2154.05 -> JASON: Okay.
2155.46 -> Select locations, that feels like a good button.
2157.83 -> DANIEL: Yeah.
2159.41 -> JASON: France.
2160.99 -> DANIEL: And we do have France.
2165.34 -> JASON: Dope.
2167.05 -> Okay.
2168.05 -> Estimated monthly checks.
2170.46 -> This is going to yell at me because it is
going to go over my limit.
2174.69 -> DANIEL: But it's fine.
2176.9 -> We're going to disable it after the stream.
2178.41 -> We're just going to set it at one minute because
2180.65 -> JASON: I don't know if it's going to let me.
2184.58 -> DANIEL: Oh, shoot.
2185.67 -> Maybe we have to go back and then change the
period to be five minutes.
2193.38 -> Hopefully.
2194.38 -> Or 15 minutes.
2195.38 -> JASON: Let's see if it will let me.
2197.47 -> It has to be 500.
2201.19 -> Check schedule this month.
2202.819 -> 500.
2203.819 -> That's, what, 30 days where we need 500 divided
by 30 days.
2212.16 -> Wait, is that what am I doing?
2219.79 -> That math is absolute nonsense.
2223.05 -> We get 16 checks a day.
2225.56 -> That means we can't even do is there a way
to say only run this for a little bit?
2232.74 -> DANIEL: No.
2235.3 -> I should probably add that as a feature request.
2239.65 -> Let's set it at six hours and see if that
works.
2241.32 -> JASON: Yeah, it will give us six hours.
2244.72 -> DANIEL: It should hopefully run once.
2250.23 -> JASON: It should hopefully.
2252.719 -> We need to navigate to do I need to deploy
this?
2257.579 -> DANIEL: Oh, yeah.
2258.78 -> That would be helpful.
2260.63 -> New Relic can't sneak up in your browser and
monitor your local host sadly.
2266.4 -> JASON: You'll have to walk me through this
part because you're going to have me deploy
2271.849 -> somewhere I don't deploy.
2276.72 -> DANIEL: I use Vercel CLI.
2282.099 -> Yeah, hit Vercel off or login.
2289.12 -> JASON: Okay.
2292.78 -> I think I have an account.
2300.359 -> CLI login failed.
2306.04 -> No Vercel account.
2309.349 -> Okay.
2312.109 -> We're going to do that real quick.
2313.849 -> What is that?
2317.44 -> Wait, I do have an account.
2321.15 -> DANIEL: That's really weird then.
2323.13 -> JASON: How do I okay.
2326.91 -> My username.
2328.42 -> What am I hooked to?
2332.19 -> Can I hook up to login connections, GitHub.
2339.54 -> DANIEL: Ah.
2342.98 -> JASON: Now I'm hooked up to GitHub.
2345.86 -> Okay, great.
2346.99 -> I'm going to close this, go back here, try
this one more time.
2352.18 -> Nope.
2354.31 -> It's happening.
2358.569 -> GitHub.
2360.69 -> Should be logged in.
2361.69 -> CLI login success.
2367.69 -> Okay.
2368.69 -> I'm in.
2369.69 -> DANIEL: Yes.
2370.69 -> JASON: And now what?
2372.72 -> DANIEL: All we have to do is hit Vercel.
2374.98 -> That's the command to deploy stuff.
2380.03 -> JASON: I haven't forked this repo or anything.
2386.75 -> DANIEL: I think you just have to click yes.
2389.79 -> You just clicked no.
2391.55 -> JASON: No.
2392.7 -> Okay.
2393.7 -> Here we go.
2403.49 -> Do I want to modify these settings?
2424.27 -> I'm assuming no.
2435.55 -> And this I assume is my yeah, okay.
2441.53 -> DANIEL: It's currently building.
2445.22 -> It will take like a couple seconds, I think,
to deploy.
2450.05 -> JASON: Okay.
2453.27 -> We can kind of watch this happen.
2457.46 -> It's doing stuff.
2462.3 -> DANIEL: It's kind of scary to see it deploy.
2468.19 -> Hopefully everything worked.
2470.99 -> Okay.
2473.22 -> We have
2474.22 -> JASON: That worked.
2475.22 -> Now if I click this button, it shows me that
one, which is not surprising.
2479.42 -> That's what it should have done.
2481.39 -> We can come back here, put this one in, right?
2484.55 -> DANIEL: Yep.
2485.63 -> JASON: And then I need to click element.
2489.589 -> DANIEL: Uh huh.
2491.48 -> JASON: By ID CSS or X path.
2495.9 -> We need to get back in here and check what's
this button called?
2509.25 -> I should probably add should we add I feel
like this is going to change every time.
2516.08 -> DANIEL: Something you can do that works for
me is have the text of the button and just
2521.829 -> put it in.
2523.069 -> Discover the truth.
2524.22 -> JASON: Okay.
2525.29 -> I can just put in
2526.29 -> DANIEL: Yeah.
2527.61 -> JASON: Text?
2529.26 -> DANIEL: Yeah.
2530.91 -> I tried that yesterday and it worked.
2533.619 -> Don't have the quotation marks.
2535.06 -> Just discover the truth, straight up.
2537.71 -> And then we can always validate it by clicking
validate.
2540.29 -> We can always validate each step of the building.
2547.56 -> JASON: Okay.
2553.13 -> And so, what we could also do, if this text
doesn't work, is add like a data attribute
2561.34 -> to the button which doesn't affect the behavior.
2564.64 -> It doesn't have to be tied to the CSS.
2566.44 -> It can be like this is a testing hook.
2568.88 -> That is a pretty common path that I've seen.
2571.05 -> We can do this without adding an ID, which
is not necessarily what we want to do.
2580.41 -> DANIEL: For sure.
2582.359 -> JASON: Okay.
2583.66 -> DANIEL: Hopefully this works.
2585.61 -> JASON: Hopefully this works.
2586.72 -> And then the other piece that we need to do
is we need to check we're asserting something,
2595.29 -> right?
2596.29 -> DANIEL: Yeah.
2597.29 -> We have to assert that the title is I guess
you can't test it while it is validating.
2607.65 -> Oh, shoot.
2609.28 -> Wow, that is taking a long time.
2614.99 -> Yeah, that's the code that powers it.
2619.22 -> JASON: This is cool.
2620.69 -> Just kind of like does the whole thing.
2622.41 -> DANIEL: Yeah, because we don't want people
oh, it worked.
2626.79 -> Okay, cool.
2627.79 -> JASON: It worked.
2628.79 -> And look, it showed us the right thing.
2630.57 -> DANIEL: Yep.
2631.74 -> JASON: Okay.
2632.9 -> That's great.
2633.9 -> DANIEL: Now let's just assert.
2635.839 -> JASON: We want to assert text.
2637.76 -> DANIEL: Uh huh.
2639.069 -> JASON: And we want to let's see.
2644.02 -> That's an H1, right?
2645.21 -> The header?
2646.21 -> DANIEL: Yep.
2647.319 -> JASON: We're going to get the H1 and insert
that the text contains sous vide.
2656.88 -> DANIEL: Can we just double check that the
header is H1?
2661.52 -> Oh, perfect.
2662.95 -> JASON: Yeah, that's what we're doing here,
is sous vide.
2667.55 -> I want to make sure I've got my I don't know
if case matters, but let's make sure it works.
2677.309 -> Okay.
2678.69 -> That should do it, right?
2681.82 -> This should validate true?
2683.16 -> DANIEL: Yes, that should for France.
2687.05 -> Let's click save.
2688.48 -> JASON: Saving.
2690.06 -> DANIEL: I'm looking down because it is kind
of small on my screen.
2697 -> I kind of look funky on the camera.
2701.26 -> JASON: All good.
2703.29 -> All good.
2704.65 -> So, does it show when one is running so that
we can make sure that it is doing the thing?
2711.04 -> DANIEL: I don't think it shows when it's running.
2716.91 -> I think it should run for the first time when
you create it.
2720.31 -> JASON: Okay.
2721.31 -> DANIEL: I think we might have to wait for
a little bit.
2724.63 -> Let me see if chat knows because I think there's
some New Relic people in here.
2729.03 -> You can trigger to check manually.
2731.25 -> JASON: Can I do that monitor results.
2739.92 -> Resources, failures.
2742.4 -> Where is my check?
2750.599 -> See full map.
2752.81 -> Go back here maybe.
2756.87 -> DANIEL: I think you might have to oh, shoot.
2767.2 -> JASON: And so, while we're doing that, I'm
going to look back through momen is saying
2779.05 -> from the Middle East, some Egyptian food.
2785.28 -> I know in between Nigeria and is it Ghana,
where there's a big feud over jollof rice.
2797.78 -> Is there an equivalent of that in the Middle
East?
2802.349 -> Egyptians will go over to how good they are
at making that thing.
2810.03 -> Oh, yeah, we make the best whatever it is.
2814.47 -> What else?
2818.279 -> I think we could do the pizza thing.
2820.8 -> That would be kind of fun.
2822.109 -> DANIEL: Like Chicago versus New York.
2824.74 -> JASON: Uh huh.
2826.18 -> That one I know we can do pretty fast because
I'm almost positive we can find Chicago pizza.
2832.369 -> Yep.
2833.76 -> Look at that casserole.
2835.42 -> (Laughter)
2836.619 -> DANIEL: Oh, my God.
2840.63 -> JASON: Let's see.
2843.1 -> This is going to work.
2844.1 -> We'll get this, open a new tab, and then let's
do New York.
2850.619 -> That looks like a New York slice.
2855.71 -> We'll do that.
2857.26 -> Is that a New York slice?
2858.92 -> It's good enough.
2862.11 -> Somebody from New York is going to fight me.
2863.869 -> Open that one in a new tab.
2865.77 -> DANIEL: Which team are you on though?
2870.3 -> JASON: My controversial opinion well, actually
it's not even controversial.
2875.469 -> It's just backed by data is that Portland
is the best pizza city in the world.
2883.02 -> The comments are heating up right now, but
there's a whole article on this.
2887.97 -> Watch, watch.
2889.52 -> Portland best pizza look, here it is.
2896.71 -> Look at this article.
2899.05 -> The best pizza city in America is Portland,
Oregon.
2901.71 -> DANIEL: The Portland pizza I've had is fabulous.
2906.089 -> It's a good in between between New York and
Chicago.
2911.79 -> The city doesn't make its entire personality
based on pizza.
2914.869 -> JASON: That's true.
2916.069 -> It just makes good pizza.
2917.18 -> DANIEL: Exactly.
2918.18 -> JASON: And the thing I like about Portland
is people from all over have moved to Portland
2922.329 -> and made excellent pizza here.
2925.37 -> A couple of people from Detroit moved to Portland
and made good Detroit style.
2934.5 -> We've got whatever lovely 50/50s is with edible
flowers.
2943.95 -> We've got the Ken Forkish and Apizza Scholls.
2951.7 -> Really good variety of pizza, which is why
Portland is the best pizza city.
2959.98 -> DANIEL: I'm headed to Portland today.
2962.549 -> Do you have any recommendations?
2964.75 -> JASON: Are you legitimately headed to Portland
today?
2967.28 -> DANIEL: Right after this stream, I have a
flight at 1:00.
2970.99 -> JASON: I will send you a list.
2975.349 -> I have a whole look, I built this website.
2978.74 -> It's called snack.tips.
2980.599 -> It's just a bunch of food in Portland.
2983.609 -> DANIEL: I love that you bought this domain.
2987.23 -> JASON: Of course, I bought this domain.
2990.65 -> I would be a fool not to buy this domain.
2993.13 -> DANIEL: It's called domain driven development,
I think.
2995.54 -> JASON: That is absolutely true.
2998.19 -> (Laughter)
2999.19 -> JASON: All right.
3000.59 -> Let me go back in here and let's take a look.
3003.23 -> DANIEL: I think I got some tips from New Relic.
3009.71 -> Do you see run check there on top?
3013.15 -> No, no.
3014.16 -> Go down there.
3017.41 -> Let's check if that worked.
3019.869 -> JASON: Here it does show zero failures, one
checks.
3023.95 -> DANIEL: It worked.
3024.95 -> Let's just go to results.
3026.75 -> JASON: Oh, results.
3028.56 -> Here we go.
3030.36 -> DANIEL: Then click the little table.
3033.589 -> JASON: Success.
3035.45 -> And look at it.
3036.45 -> Here we go.
3037.45 -> Here is our waterfall.
3039.99 -> We can see 182 kill kilo bytes.
3047.48 -> We have a script log.
3053.72 -> That's also cool.
3055.28 -> DANIEL: We may have to rerun it.
3059.4 -> There's some quirks with the platform.
3061.18 -> JASON: This is cool.
3063 -> It shows those bits.
3065.91 -> DANIEL: Even though we're using synthetics
for a fun purpose today, it's really useful
3073.64 -> when you're trying to build a website that's
accessed by people from all over the world
3077.809 -> so you don't have to manually test everything.
3079.92 -> You can get alerted when things go wrong.
3083.24 -> You can go fix the issue before a lot of your
customers start complaining on Twitter.
3089.98 -> JASON: Anything that can tell you something
is happening before your customers do is good.
3097.38 -> Because the worst way to find out something
is wrong is to have somebody email you and
3103.89 -> be like, hey, your thing is broken.
3106.21 -> Let's see.
3107.38 -> We've got another one.
3109.7 -> Do we need to tell it to grab the screenshot?
3111.849 -> DANIEL: No.
3112.849 -> It should do it automatically.
3115.109 -> For some reason, it's not grabbing it.
3118.369 -> Okay.
3119.369 -> That's really weird.
3120.369 -> If the check is successful, that means the
header was there and people from France are
3128.37 -> able to see sous vide burgers are the superior
burger, which is not true.
3134.75 -> (Laughter)
3135.85 -> DANIEL: Because we don't boil burgers.
3139.74 -> I didn't know that boiled burgers were a thing,
but apparently that's a thing.
3144.609 -> JASON: I don't know.
3145.609 -> I've never understood the appeal of a meat
bath.
3151.73 -> DANIEL: The thought of a meat bath is creeping
me out, but okay.
3155.88 -> Now that we have a couple more minutes do
you want to start building the pizza or the
3160.5 -> Egyptian food or whatever chat wants us to
build?
3162.89 -> JASON: Let's do it.
3164.27 -> DANIEL: What food should we focus on?
3166.68 -> JASON: I think maybe momen dropped because
I didn't hear anything back about the Egyptian
3172.28 -> food, so let's do pizza because that is one
that I understand.
3176.869 -> I am going to create a new file called "pizza,"
and I'll just copy my index.
3185.73 -> This one is going to say "pizza" what's a
good P word?
3197.56 -> Pizza punchout.
3200.52 -> DANIEL: Pizza punchout.
3204.99 -> I like it.
3205.99 -> It's slightly aggressive.
3207.29 -> JASON: It is very aggressive.
3209.25 -> Chat, maybe give us a better one.
3211.15 -> I am going to think of let's see.
3216.859 -> I shouldn't have put myself on the spot to
be clever.
3222.2 -> This is not going to work out.
3224.77 -> I'm going to fill out these while I think.
3226.6 -> We've got New York style and Chicago style.
3231.17 -> DANIEL: New York style.
3233.68 -> I think someone in the chat said Naples for
Italy.
3238.829 -> JASON: Neapolitan, yeah.
3243.15 -> We can do the country base you mean?
3246.39 -> DANIEL: Or we can do city base.
3248.619 -> JASON: Can we do city based?
3250.54 -> Because I think city based would be fun to
show.
3254.27 -> DANIEL: Yes.
3257.89 -> JASON: Slice thin, crispy, delicious.
3265.61 -> DANIEL: You're a New York style fan?
3269.26 -> JASON: I like all pizza.
3271.67 -> DANIEL: Even casseroles?
3274.589 -> JASON: Oh, yeah.
3277.51 -> I'll talk a whole bunch of crap on Chicago
style pizza and then I will absolutely eat
3285.24 -> one.
3286.24 -> DANIEL: I was in Detroit last year.
3291.51 -> I really like Detroit style pizza.
3293.02 -> JASON: Detroit style pizza is killer.
3297.839 -> I have yet to be to Detroit, so I look forward
to the day that I get to have the real deal,
3303.049 -> but I've been to Detroit style pizza places
in a few different cities.
3308.069 -> I love the style.
3310.119 -> There's a good spot up here if you want to
get a good Detroit style pizza.
3312.57 -> It's called East Gleason Pizza.
3315.13 -> DANIEL: You're the expert on pizza.
3317.869 -> I love it.
3319.599 -> JASON: Chicago style pizza, deep dish, loaded
with flavor for cheese fans.
3334.17 -> How about that?
3337.23 -> Yes, good enough.
3340.29 -> I think I can just hot link some of these.
3346.79 -> Let's make it square.
3347.79 -> Now I've got to remember how image X works.
3350.38 -> We're going to go to I'll go down here.
3356.05 -> 500.
3357.099 -> Height is going to be 500.
3368.7 -> You want prop to be entropy, I think.
3382.26 -> Should give us a good one.
3383.6 -> DANIEL: What are you doing right now?
3387.75 -> JASON: This is ImageX.
3390.96 -> Unsplash uses it under the hood.
3394.079 -> You have these options to do different types
of crops and stuff.
3398.5 -> If it is a picture of faces, you can focus
on the faces and all that.
3402.19 -> And so, if you want a specific size of image,
you can take the image and apply some different
3409.51 -> filters.
3410.51 -> What I did at the end here is I just changed
the width and height to 500 so it is the right
3416 -> size and then set crop to entropy because
it is the most visually interesting piece
3421.26 -> of the image.
3422.54 -> Now I don't have to drop in a giant image
and hope for the best.
3428.869 -> I can just drop this right in here and that's
going to work.
3431.92 -> And then for the New York style, we can do
the same thing.
3434.24 -> I'm just going to copy/paste this to avoid
making everybody watch me do that twice.
3441.539 -> We'll go into here
3443.18 -> DANIEL: I love it.
3446.69 -> JASON: And then down at this side.
3450.289 -> Just grab everything from the width, paste.
3454.799 -> This one actually, the entropy might screw
us because this is going to be pretty visually
3458.54 -> interesting.
3459.54 -> Let's see.
3461.8 -> What we'll do instead is we will use bottom.
3464.94 -> DANIEL: Oh, that's good.
3470.099 -> That looks really yummy actually.
3476.55 -> JASON: I love a good pizza by the slice.
3480.17 -> It's such a deceptively hard thing to make.
3484.26 -> It feels like people try to make pizza by
the slice and then it is a real disappointment.
3493.53 -> You can't go wrong with pizza, but which style
reigns supreme?
3510.93 -> Then we're going to go in here to our site,
which is not running anymore.
3516.13 -> We'll npm run dev.
3521.839 -> And I want to go to pizza punchout.
3527.38 -> DANIEL: How did you create the image in the
logo on top?
3532.23 -> It looks really nice.
3533.26 -> Is it like a gif?
3534.26 -> JASON: These are little images I create sometimes
to keep from doom scrolling on Twitter.
3542.66 -> I used a gif creator doing two versions, like
rotating back and forth.
3547.069 -> DANIEL: Oh, wow.
3549.079 -> That's really smart.
3550.55 -> JASON: I could have used svg, but then I was
like I'm not spending that much time on this.
3557.38 -> DANIEL: Nice.
3560.21 -> JASON: Okay.
3563.049 -> My alt tags are incorrect.
3569.78 -> Let's see.
3573.839 -> Style, pepperoni pizza, deep dish pizza with
a cheesy slice being lifted out of the pan.
3593.97 -> Now we've got alt text is actually useful.
3598.849 -> DANIEL: Somebody asked what we're building.
3601.52 -> We're building a website that tells you, depending
on where you're visiting the website from,
3607.16 -> what is the best type of a pizza.
3609.309 -> Folks from New York will get New York style
pizza and Chicago people will get Chicago
3616.46 -> style pizza.
3617.46 -> JASON: Yeah.
3618.46 -> We're in the midst of adding the pizza version,
but we've done so far is this burger version.
3623.4 -> If you load from anywhere in the world except
France, you'll see the Smashburger page.
3628.869 -> If you load from France, which we picked arbitrarily
because sous vide is, I believe, a French
3636.71 -> word.
3638.099 -> If you go from France, you'll see the sous
vide page.
3642.589 -> Now we're working on the same thing but for
pizza, and we're going to set up by city.
3648.349 -> We want to look at New York and Chicago as
the cities we want to show.
3654.22 -> We need our answer page, which we can get
out of here.
3658.04 -> I'm going to grab this one and duplicate it.
3664.26 -> For this, what I'm going to do is actually
just do an answer dot NY and answer dot Chi.
3677.92 -> Then we can head over to the pizza page, grab
New York style out of here, go to New York.
3694.77 -> Watch me alienate all of my New Yorker chat
members.
3702.349 -> They all just logged off like right now.
3709.099 -> Then we'll do the same thing for Chicago style.
3718.68 -> Now Chicago has logged off.
3730.119 -> What we need to do then is update the middleware,
right?
3732.4 -> DANIEL: Yep.
3733.4 -> JASON: Maybe walk me through how we want to
do this because here's how I want this to
3738.049 -> work, like what I'm envisioning in my head.
3741.71 -> Everybody who is not in New York and not in
Chicago should still see the burger page,
3747.91 -> but if you're in New York or Chicago, I want
to show the pizza page.
3751.66 -> The home page should shift for New York and
Chicago to show the pizza page.
3755.6 -> And then if you're in New York or Chicago,
when you click "discover the truth," I want
3763.68 -> to show either the New York page or the Chicago
page based on which one you're in.
3769.11 -> DANIEL: I need you to repeat that so I can
write it down.
3773.869 -> JASON: If the city is Chicago or New York,
show the pizza home page instead.
3786.58 -> DANIEL: Uh huh.
3789.16 -> JASON: Else show the default home page.
3791.92 -> DANIEL: Uh huh.
3793.609 -> JASON: Then if city is Chicago, show Chicago
answer page.
3806.54 -> Else if city is New York, show NY answer.
3815.7 -> Basically, if we get we would need a block
that's like if if we do if req dot geo dot
3830.2 -> city do we just get this?
3838.17 -> Do you know how this works?
3839.22 -> DANIEL: Oh, I have no idea, which makes it
really fun.
3843.88 -> I think we can just log it out.
3845.631 -> I think we can just use logger.
3847.789 -> I'm very excited to try it.
3850.24 -> JASON: Here's what I want, is to do this check,
right?
3856.18 -> DANIEL: Uh huh.
3857.18 -> JASON: If we're here, then we would set I
want my matcher to have like multiple matches.
3867.21 -> I do one of these, and then we'd need to if
this
3877.28 -> DANIEL: So, you can do conditionals.
3886.22 -> You can do you have to add the matcher all
the routes you want to change into matcher.
3896.52 -> Do you see rewrite at the very bottom, like
return rewrite?
3902.13 -> You can actually insert custom logic there.
3905.97 -> We'll have to now have multiple return statements
for everything we want to return.
3912.96 -> Inside of that if statement, we'll have to
add a return statement.
3916.49 -> We have to copy and paste that in there.
3918.859 -> And then basically return next response rewrite.
3925.79 -> Instead of req dot next dot URL, we have to
write new and then capital URL, bracket parentheses,
3933.15 -> then
the URL you want to transform, comma, transfer
3940.22 -> URL.
3941.22 -> JASON: Okay.
3942.22 -> DANIEL: Does that kind of make sense, what
I'm trying to do?
3948.46 -> JASON: It makes sense, and then I'm just melting
my brain right now because we have to let's
3955.52 -> see.
3956.52 -> How are we doing on time?
3957.52 -> We're doing great on time.
3959.49 -> We need to check if looking at the home page
3969.76 -> DANIEL: How about this?
3973.39 -> If it's in the U.S., it goes to pizza and
for everywhere else it guess to burgers.
3983.96 -> JASON: Yeah, we can do that, but we would
miss the Chicago/New York check.
3992.049 -> We need two pieces.
3994.23 -> We need to check if they're looking at the
home page one set of redirects.
3999.52 -> And then if we're looking at the answer page,
we need a second set of redirects.
4008.039 -> This is actually if looking at the answer
page, we would need to check if the geo country
4016.039 -> is France.
4017.4 -> Then it would be else if
4018.69 -> DANIEL: We actually can't keep line 11 and
13 because we have multiple URLs that we're
4034.599 -> trying to transform.
4035.91 -> It's not just one thing.
4038.109 -> We're trying to change to two things we want
to change the base as well as the answer.
4044.859 -> We actually have to put we need to just return
the next response, rewrite with the URL we
4053.4 -> want to transform it to.
4054.74 -> Does that make sense?
4055.859 -> JASON: Yeah.
4056.859 -> We need to return next response.
4058.23 -> DANIEL: Rewrite.
4059.65 -> JASON: Rewrite.
4061.069 -> DANIEL: And then
4062.069 -> JASON: New response.
4065.45 -> DANIEL: No, it's new URL.
4068.89 -> It's a new URL object.
4071.13 -> Then you have to open the parentheses.
4073 -> Then it would be the URL you want to redirect.
4076.72 -> It would be that, comma, and then the request
dot URL or req dot URL.
4085.329 -> JASON: Oh, I see, so we get like the base
path.
4089.33 -> DANIEL: Exactly.
4090.49 -> JASON: Okay.
4091.66 -> Got you.
4092.77 -> Then we'll take this one and do the same thing
here for answer.
4099.06 -> We can get rid of this.
4100.06 -> We can get rid of this.
4102.96 -> DANIEL: Exactly.
4103.96 -> JASON: If the geo city is Chicago, we would
want to duplicate this a couple of times.
4112.64 -> DANIEL: Imagine the state machines of this.
4116.48 -> Oh, my gosh.
4117.859 -> JASON: What have I done?
4119.5 -> Oh, I did a thing I shouldn't have done.
4121.74 -> We're going to take this, copy/paste.
4123.9 -> That's going to be New York and that's going
to be our else statement.
4129.28 -> DANIEL: This is machine learning, right?
4132.259 -> A bunch of if else statements.
4134.48 -> JASON: Exactly.
4137.029 -> Nobody knew this was how it was going to go,
but I just started an AI company today.
4144.79 -> DANIEL: I was looking for air fryers online.
4149.929 -> Everybody was like AI air fryers or AI rice
cookers.
4154.799 -> What are you trying to do?
4163.55 -> JASON: This is me checking that we're trying
to go to the answer page.
4168.679 -> DANIEL: Oh, no.
4170.21 -> We don't have to do that because the do you
see the new URL?
4178.089 -> The first part of the statement, the quotation
mark, is the URL you're trying to redirect.
4184.44 -> You don't need to check
4185.63 -> JASON: This is the URL we need to redirect?
4189.69 -> DANIEL: Yes.
4191.029 -> JASON: Because that's not going to match then.
4195.72 -> If I want to change, when we visit the index
page, New York or Chicago, we want to show
4202.46 -> them pizza.
4203.46 -> DANIEL: Oh, sorry.
4204.46 -> I just had a brain farther.
4206.36 -> brain fart.
4207.36 -> Yes.
4208.36 -> Yeah, yeah, yeah.
4209.36 -> JASON: This one, we need to check the path
name?
4213.909 -> DANIEL: Next URL dot path name.
4216.73 -> JASON: Next URL dot path name.
4219.17 -> That would be this, right?
4223.71 -> DANIEL: Yes.
4225.53 -> JASON: Okay.
4227.35 -> And so, then the next piece would be to take
this this would be answer.
4236.459 -> And then we're going to take this whole thing
and try again.
4240.88 -> DANIEL: Wait.
4241.88 -> Should we just test this part first before
we do that?
4245.21 -> JASON: Yeah.
4246.57 -> We can test anything you want.
4249.26 -> And then this would be I'm just going to delete
this is what the code should be.
4259.659 -> I don't know if my exact setup here is correct,
but this is like the logic that we're after.
4265.98 -> Why are you mad?
4270.56 -> Or.
4274.34 -> Right?
4278.12 -> This would be pizza and this would be root.
4281.49 -> This is at least pseudo logic.
4285.32 -> DANIEL: It looks correct.
4288.28 -> I'm excited to try it.
4290.1 -> JASON: Okay.
4291.1 -> Let's give this a shot and see what we can
get here.
4294.31 -> I'm going to attempt to load the home page,
and that is doing what I want.
4301.71 -> Now I'm going to just try, for the sake of
okay.
4311.62 -> Let's log this.
4318.08 -> Req dot geo.
4319.4 -> Don't tell me you can't do stuff.
4326.82 -> Okay, fine, computer.
4330.709 -> You're right this time.
4333.05 -> Where's my geo?
4334.08 -> Does it show up in the browser?
4336.92 -> DANIEL: I think so.
4339.98 -> JASON: I think I may have missed I may have
screwed this up.
4349.01 -> DANIEL: Do you want to do just req dot geo
dot city?
4353.32 -> I think it is like a JSON
4361.219 -> JASON: Undefined.
4363.47 -> That's probably because we're local, right?
4367.179 -> DANIEL: Yeah.
4369.48 -> I think we have to deploy it on Vercel.
4371.68 -> Let's try that.
4372.92 -> JASON: Let's see what happens.
4374.97 -> Oh, let me turn off the Portland part.
4376.83 -> We'll go to Chicago and then let our synthetics
do the work for us.
4381.5 -> I'm just going to type Vercel.
4398.15 -> And we're doing it.
4400.37 -> We're going.
4401.37 -> It's happening.
4403.139 -> There we go.
4405.91 -> If I come back out here
I think that part is working at least.
4417.88 -> Let's go build our synthetic and try it out.
4419.87 -> DANIEL: Yes.
4420.87 -> JASON: I do this synthetic monitoring.
4423.31 -> I don't build it inside.
4425.46 -> I do a new one, right?
4427.13 -> DANIEL: Yeah, you build a new one.
4429.699 -> JASON: Okay.
4430.699 -> This one is going to be we'll do the same
thing here.
4433.06 -> We'll call it food feud pizza.
4437 -> Got to set it to six hours again.
4443.75 -> 12 hours, one day.
4446.28 -> DANIEL: It still won't let you?
4450.09 -> JASON: Oh, I know what it is.
4454.52 -> We haven't set a location yet.
4455.92 -> DANIEL: Oh, okay.
4456.92 -> JASON: Select the location, and this time
we're going to set oh, crap.
4461.13 -> DANIEL: Chicago.
4462.6 -> There's no Chicago.
4464.8 -> JASON: There's no Chicago or
4467.81 -> DANIEL: We may have to change the code so
it is Portland and
4473.62 -> JASON: Yeah, let's change the code to Portland
and San Francisco.
4479.78 -> DANIEL: Uh huh.
4484.92 -> JASON: Portland, San Francisco.
4498.02 -> The same thing for this one.
4501.48 -> DANIEL: I really hope this works.
4506.389 -> JASON: I really hope this works too.
4507.88 -> I'm very excited to try it.
4510 -> Let's deploy one more time.
4512.58 -> Oh, come on.
4514.68 -> DANIEL: Vercel.
4516.08 -> JASON: Portland and San Francisco.
4518.679 -> Right?
4519.679 -> I can do them both?
4520.679 -> DANIEL: Yeah.
4521.679 -> Yep.
4522.679 -> JASON: Okay.
4523.679 -> We're going to define the steps.
4524.679 -> We're going to navigate to our website.
4530.91 -> Right?
4533.449 -> And then we're going to click an element,
and that's going to be "discover the truth."
4540.78 -> And then we're going to assert text.
4547.989 -> How do I can I do conditional?
4551.67 -> DANIEL: Not with this view because this is
the no code.
4557.27 -> You can't do conditional.
4558.27 -> We can just expect one to succeed and one
to fail.
4562.4 -> JASON: Okay.
4564.8 -> We're going to locate the H1.
4567.54 -> DANIEL: Uh huh.
4568.6 -> JASON: And make sure that it contains what
did I say Chicago style.
4579.11 -> I think Portland will get Chicago style and
San Francisco will get New York style.
4584.56 -> I think that's the way that we replaced that.
4586.739 -> Should I try validate or save?
4589.64 -> DANIEL: We can validate.
4592.33 -> No, let's just save.
4595.02 -> Let's just save.
4597.03 -> I trust us.
4599.05 -> JASON: Okay.
4600.389 -> I trust us too, Daniel.
4603.04 -> All right.
4605.139 -> Let's see how this thing is going.
4606.24 -> We've got waiting on checks to run.
4610.29 -> DANIEL: I think you should run
4613.27 -> JASON: This is also deployed now.
4617.11 -> I'm seeing pizza.
4618.9 -> Okay.
4620.19 -> Now let's try again.
4621.27 -> Let's see what happens.
4622.46 -> Hey!
4623.46 -> DANIEL: Oh, shoot.
4625.06 -> It worked!
4626.36 -> JASON: First try.
4628.32 -> DANIEL: Wow.
4629.62 -> That never happens livestream.
4632.23 -> That is impressive.
4633.23 -> Wow.
4634.23 -> (Laughter)
4635.23 -> DANIEL: Wow.
4636.23 -> I am impressed.
4637.23 -> JASON: I can't believe that worked.
4640.59 -> This is wonderful.
4641.69 -> If anybody wants to try this to validate,
hit this up if you're not in Portland or San
4647.63 -> Francisco.
4648.77 -> You should be able to try this and still see
the burgers.
4652.23 -> Give it a shot.
4653.23 -> DANIEL: In San Francisco, what should I see?
4656.06 -> JASON: If you discover the truth, you should
be seeing pizza and New York style.
4659.51 -> DANIEL: It does.
4660.51 -> It does.
4661.51 -> JASON: What?
4662.51 -> DANIEL: What?
4663.51 -> JASON: Look.
4664.51 -> We're the best programmers on the planet.
4667.12 -> DANIEL: Honestly, yeah.
4669.05 -> (Laughter)
4670.05 -> DANIEL: I want to show my screen.
4673.65 -> Look.
4674.65 -> JASON: Unbelievable.
4675.76 -> Look at us go, everybody.
4677.21 -> This is brilliant.
4678.58 -> I am so happy that that worked on the first
try.
4684.02 -> DANIEL: That never happens, Jason.
4687.31 -> Jason, you're like next level.
4689.98 -> JASON: (Laughter).
4691.05 -> Okay.
4692.05 -> Are you done?
4693.179 -> We've got a failure.
4695.31 -> Good, good, good.
4696.909 -> That's what we wanted.
4697.909 -> Now we'll go to results.
4700.07 -> We've got a failure.
4702.78 -> The Portland check.
4704.09 -> DANIEL: Yeah, I got burgers.
4706.52 -> Yes!
4707.52 -> Let's go.
4708.56 -> JASON: Wait, this one should have worked.
4712.1 -> DANIEL: Wait.
4713.159 -> JASON: This one's Portland, right?
4715.17 -> DANIEL: Yeah.
4716.29 -> JASON: Right?
4717.41 -> We loaded from Portland.
4720.25 -> That should have
4721.75 -> DANIEL: Maybe it ran before it deployed.
4725.449 -> When did it run?
4726.61 -> JASON: Maybe.
4727.84 -> Let's try it again.
4729.08 -> DANIEL: You're trying it from Portland, right?
4731.93 -> And it showed the right thing.
4734.41 -> JASON: One of two locations failing.
4737.739 -> DANIEL: Hmm.
4740.42 -> I got excited before it loaded.
4744.449 -> JASON: I know.
4746.26 -> This is good.
4747.26 -> We're still one of two locations failing.
4749.87 -> Does it round robin these where it tries each
one?
4755.679 -> DANIEL: Yeah.
4759.199 -> Hopefully it works.
4760.26 -> JASON: Okay.
4761.44 -> Here's our second one.
4762.46 -> DANIEL: Oh, it still failed.
4764.42 -> That's really weird.
4765.59 -> JASON: It still failed.
4767.15 -> Here's what I don't know.
4771.44 -> We're going to have to look at the Vercel
logs, assuming I can figure out how this works.
4777.21 -> Let's go to Vercel.
4779.69 -> Then we've got this site here and then logs.
4786.56 -> DANIEL: Yeah, view build and function logs,
I think.
4792.409 -> Oh, it's realtime.
4794.57 -> JASON: It's realtime.
4797.21 -> Okay.
4798.21 -> Let me try it.
4800.199 -> I've hit it.
4804.86 -> Anything?
4806.42 -> Hello?
4807.969 -> DANIEL: Can we try revisiting the site instead
of reloading it, maybe there's some caching
4819.61 -> going on.
4820.639 -> JASON: Perhaps, perhaps.
4823.07 -> Okay.
4824.07 -> Let me close this, open a new window, try
again.
4832 -> Show me some logs.
4835.239 -> DANIEL: Wait.
4836.87 -> Did we do console logs where it only shows
up in the console?
4842.01 -> JASON: I console logged from middleware, which
should show up in the logs.
4849.62 -> I don't know how Vercel does this.
4851.739 -> DANIEL: Me neither.
4854.47 -> I just deploy my portfolio.
4857.92 -> Shoot.
4860.239 -> Should we exit out of middleware?
4866.95 -> Let me try it again.
4870.23 -> I'm like reloading the website.
4872.61 -> Oh, wow.
4874.719 -> JASON: Okay.
4876.84 -> It's mostly working.
4879.86 -> Check logs and synthetics.
4881.15 -> Do we get logs in synthetics?
4884.46 -> DANIEL: Yeah.
4886.989 -> JASON: Unexpected token.
4893.11 -> That's like Vercel's junk.
4894.81 -> DANIEL: Yeah.
4895.94 -> JASON: Oh, wait a minute.
4898.76 -> Wait, why would Vercel be why would you put
that in my production site?
4904.81 -> Don't do that.
4906.44 -> DANIEL: What is next life feedback?
4910.01 -> JASON: Isn't that their commenting overlay
thing?
4914.83 -> DANIEL: Yeah, I think so.
4916.83 -> JASON: So why is that in my production site?
4919.28 -> DANIEL: Yeah, that is concerning.
4922.9 -> What is the URL that we're testing?
4925.2 -> JASON: Isn't this my wait, which one is which?
4930.6 -> DANIEL: I think the top one is what you're
supposed to share out.
4933.93 -> JASON: Always up to date view of this branch.
4938.2 -> Unique view of this deployment, but what I
want is my actual URL.
4944.42 -> Project deployment, domains.
4947.81 -> Maybe I need this one.
4949.33 -> Okay.
4950.33 -> Let's try this one more time.
4952.57 -> Oh, see.
4953.57 -> This one didn't work.
4956.6 -> Okay.
4958.19 -> Maybe now we get logs.
4960.58 -> Why does that only work that works in one
version and not the other.
4970.1 -> Do I have to promote something hello?
4975.4 -> Food feuds.
4977.01 -> Deployments.
4978.33 -> This is the one
4979.33 -> DANIEL: Eight minutes ago.
4983.36 -> Yeah.
4984.46 -> It's not automatic?
4987.77 -> JASON: Apparently not.
4991.08 -> Okay.
4992.19 -> Let's try this one more time.
4995.739 -> DANIEL: My dog is just joining the stream.
4999.96 -> JASON: Oh, that's good.
5002.76 -> Okay.
5004.05 -> Unfortunately, we ran out of time, and I'm
going to blame this one on Vercel not really
5009.55 -> making sense.
5011.429 -> Oh, now it's working.
5013.39 -> We're going to have to check the synthetics
later, but that was a Vercel problem and not
5017.449 -> a New Relic problem.
5019.34 -> With that, we're going to call that a success.
5021.5 -> Daniel, thank you so much for taking time
with us today.
5024.39 -> This was a ton of fun.
5025.85 -> I had a lot of good laughs on this stream.
5028.949 -> Chat, I hope you enjoyed this as well.
5031.14 -> If people want to learn more about this, where
should they go next?
5034.69 -> DANIEL: If you want to learn more about synthetics,
you should check out the docs link I am dropping
5041.85 -> right now into the chat.
5044.16 -> And if you want to learn more about Next.js
and all the goodies you can do, check out
5049.78 -> the Next.js documentation, especially the
server documentation.
5052.45 -> I think you can do a lot of cool personalization
stuff.
5057.16 -> Hopefully, maintain your friendships.
5060.3 -> Don't let food divide friendships.
5062.07 -> I think that's the lesson I want to impart
on everyone before I leave.
5067.639 -> (Laughter)
5068.639 -> DANIEL: I don't know.
5069.77 -> All of my friends and I that hang out a lot,
we have similar tastes in food.
5075.57 -> I think food is a big part of my friendships,
but don't let it divide you.
5080.05 -> JASON: I have definitely noticed I've become
better friends with people who eat I'm not
5087.28 -> saying I won't be friends with a picky eater,
but I definitely hang out more with people
5090.38 -> who aren't.
5094.51 -> This was super fun.
5095.53 -> Thank you so much for hanging out today.
5097.07 -> I'm going to do one more shout out.
5099.01 -> We've had Tess from White Coat Captioning
all day here.
5102.28 -> That's made possible through the support of
our sponsors.
5111.94 -> This has been O11y Week.
5113.55 -> These last three episodes have all been about
observe observability.
5117.59 -> Thank you, New Relic, for making that possible.
5120.69 -> Daniel, you're going to come back later this
month.
5127.51 -> DANIEL: Yes.
5129.45 -> JASON: We'll come back and cause more chaos.
5132.239 -> Thank you all so much for hanging out today.
5134.78 -> See you next time.
5136.43 -> DANIEL: Bye.
Source: https://www.youtube.com/watch?v=7QsRGE_TSrw