Next.js 12 - Middleware & Edge functions explained

Поделиться
HTML-код
  • Опубликовано: 12 сен 2024

Комментарии • 96

  • @JamesQQuick
    @JamesQQuick 2 года назад +19

    Hilarious that this is the video that I decided to watch and you referenced my tweet lmao! Nice job!

  • @xHomu
    @xHomu 2 года назад +6

    Thanks for putting this video out! It really helps to have someone who's willing to explain it "like I was 5" for the rest of us.

  • @yhr4052
    @yhr4052 2 года назад +10

    Thank you for this tutorial.
    Seeing this in practice is - in my opinion - more intuitive than all that fancy stuff in the documentation.

  • @MaxProgramming
    @MaxProgramming 2 года назад +1

    Thanks learnt very useful info from this video Tuomo. The Edge joke was too funny 😂.
    But yet I personally love using it 😉

  • @toastrecon
    @toastrecon 2 года назад

    Lol. When you started talking about “Edge” I stopped the video and checked to make sure I was in the right place. 😂
    Thanks for this video!

  • @rism8345
    @rism8345 2 года назад +2

    Great video! We need more content like this. Keep it up

  • @aggbits
    @aggbits 2 года назад +1

    Thank you for the video.. The thing is that with cdn.. this works very well because the CDN is the end point... but when we discuss about accessing apis, what matters most is where the api endpoint is located, not necesarlly from where the request is made.. but technically speaking if the edge function is doing the rendering also, this could save some time, and I guess that this is where server components fit in..Also it depends on how complex is the backend for your app.. if you own the auth or api service and you deploy the node server close to it without using vercell, I think that the response time would be about the same, but if you use a 3rd party auth service that also knows to handle request via geolocation, your response time improves a lot because the edge function is closer to the client and also the api endpoint is closer to the edge function. Where this fits very well for example is doing authentication with firebase because the bundle zise of the sdk will be separated from the app, I think

  • @flibben
    @flibben 2 года назад

    Very nice video, thanks for this. Exactly what I was looking for about middleware in nextJS. Loved the part about "hey, sue me", laughed out loud on that one :D

  • @WassimBenzartiPROD
    @WassimBenzartiPROD 2 года назад

    10:54 "I know this is a bit ugly, but ... hey sue me" 😂

  • @Rodrig79863
    @Rodrig79863 2 года назад +2

    amazing tutorial. Straight to the point and easy to follow

  • @matthewyak
    @matthewyak Год назад

    Thank you for this tutorial! This helped me understand much better than any documentation or google searches. 👍

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  Год назад +1

      Thanks for letting me know, that’s great to hear!

  • @gtanmoy
    @gtanmoy 2 года назад +4

    Please make a complete app in Next.js with all the updated functionality. Thank you.

  • @Rex-li5vk
    @Rex-li5vk 2 года назад

    Very informative! Not sure if I understood Edge functions during the Next.js conf 2021 but if I did I definitely forgot lol. I have a good idea of them now. Thanks!

  • @adeyemiadeyanju2247
    @adeyemiadeyanju2247 2 года назад

    😂😂😂😂 Love the Edge humor, Great video thank you earned a subscriber

  • @christopheanfry2425
    @christopheanfry2425 Год назад

    Thank you for your explanations much clearer with a well explained situation. Really good job 👍

  • @techjandro
    @techjandro 2 года назад

    I cracked in the edge joke XD thanks a lot for this video, helpful!

  • @phyllis3198
    @phyllis3198 2 года назад

    Great video, I agree with the other comments you explain this topic topic better than the NEXT.is docs. Thanks

  • @danielcrespo5897
    @danielcrespo5897 2 года назад +1

    Another great video! Thanks a lot for sharing

  • @MarcelPirosca
    @MarcelPirosca 2 года назад

    Thanks for clarifying this man, much appreciated.

  • @adedoyin3284
    @adedoyin3284 2 года назад +1

    i lauged hard with the edge joke!!!

  • @josephb7055
    @josephb7055 2 года назад

    That's a really good explanation. Keep up the good work Tuomo! What theme do you use btw?

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      Thanks Joseph, great to hear! It's the Aura theme, here is a video I made about it: ruclips.net/video/6C26mVeDjxo/видео.html

  • @victorconrado8618
    @victorconrado8618 2 года назад

    your video its de exactly what i was looking for! thx!

  • @exploring.the.world2023
    @exploring.the.world2023 2 года назад

    Thank you for the video. I want to learn next

  • @SamFromaway
    @SamFromaway 2 года назад

    Great explanation. Thanks for the video.

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      Cheers!

    • @SamFromaway
      @SamFromaway 2 года назад

      @@TuomoKankaanpaa I also mentioned your video on the one I just recorded ;)
      ruclips.net/video/RaaSmWPmjM0/видео.html

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      @@SamFromaway Thanks man!

  • @TheRDB46
    @TheRDB46 2 года назад +1

    Appreciate the view mate

  • @garymcbride2090
    @garymcbride2090 2 года назад

    Well done and thanks - well explained.

  • @krisorsmso5094
    @krisorsmso5094 2 года назад

    Hey Great video! Hmm.. I was just wondering if you're located at Helsinki, the closest vercel's datacenter is located at Stockholm?. When you deployed your app to vercel - didnt you choose its default location to be at Stockholm's dc? So in conclusion - It seems to me that there isn't much benefit for users in Finland when the backend lambdas are deployed to stockholm anyway.
    Greetings from Estonia.

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      Hey Kris and thanks for your comment! I'm not actually sure if the closest datacenter is in Stockholm, but if it is, then yeah for users from Finland that might not have a big effect. But since we don't know where users are going to open up your app, then in that case the edge functions are good option.

  • @i_dont_likevodka3062
    @i_dont_likevodka3062 2 года назад

    cool cool! thanks for the video

  • @santosharakere
    @santosharakere 2 года назад

    Excellent demo, Thanks.

  • @muhammadshahzad8852
    @muhammadshahzad8852 2 года назад

    Thanks for explanation.

  • @giftkfoote9116
    @giftkfoote9116 Год назад

    thank you, it is very helpful

  • @DanielRios549
    @DanielRios549 2 года назад

    I'm facing a problem using next-pwa and middleware, I verify if the user is authenticated on index and redirect to /login if does not, but after make the login Router.push('/') does not redirect back to index because the value of start-url cache is empty, it turns empty when the middleware redirects to /login before the user finishes the login

  • @DennisPeters39
    @DennisPeters39 2 года назад

    Thank you. You helped me a lot.

  • @igdev6095
    @igdev6095 2 года назад

    On production I can't clear multiple cookies like
    NextResponse.clearCookie('access_token').clearCookie('access_token')
    It's only clear first cookie is 'access_token' not both
    But it's work perfectly on local dev. How can I solve that? :(

  • @alexchud
    @alexchud 2 года назад

    How does middleware work after the app hydrates for pages ? Does it always make a request to the server or will it run in the browser ? How middleware works with nuxt.js for example … thanks 🙏

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад +1

      That's a good question! I would say that it won't run in the browser since the middleware is run before the page plus middleware can have logic like authentication handling.

    • @alexchud
      @alexchud 2 года назад

      ​@@TuomoKankaanpaa thanks for your reply, that's interesting, that means after the App is hydrated it still makes a call to the server for every new page that is displayed in SPA mode...

  • @geeksy2278
    @geeksy2278 2 года назад

    Whats the theme? I love it!
    Great Video. Next.js 12 is so awesome!

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      Thanks! It's Aura Dark marketplace.visualstudio.com/items?itemName=DaltonMenezes.aura-theme

  • @qbek_san
    @qbek_san 2 года назад

    _middleware edge function don't work in dev server? You need to deploy it to Vercel?

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      The _middleware should work with dev server too

  • @INSTRNT
    @INSTRNT 2 года назад

    What if we need to get the req.body.

  • @artursradionovs9543
    @artursradionovs9543 2 года назад +1

    Amazing video!
    Does it mean that no backend needed at all for a single web app? I am a new starter, and would like to learn how to develop an e-commerce app. Trying to find the best option, and this seems to be the most suitable.

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад +1

      Thank you! Basically the api & edge functions are run on backend but you don’t need to worry about setting the backend up because next.js and vercel handle that automagically. Next.js is great for an ecommerce app!

    • @artursradionovs9543
      @artursradionovs9543 2 года назад +1

      @@TuomoKankaanpaa do you reckon if it is possible to send over a verification link to email without node.js?

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      With api routes it should be possible and with edge functions I’d say if it is not possible directly, you could always use some 3rd party api to do the mail sending e.g. mailgun or something similiar.

  • @AntNZ
    @AntNZ 2 года назад

    Help! Do you have to deploy to vercel in order to use middleware\edge functions? I have tried to find an answer to this question everywhere but have not had any success. I want to deploy my app on firebase, but really need to use all of nexts features.

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      I'd say that you don't need to deploy to vercel in order to use middleware, but where ever you want to deploy needs to support middleware and edge functions. Not sure about firebase, but at least Netlify seems to support middleware www.netlify.com/blog/2021/10/27/use-next.js-12-on-netlify/ About the edge, Netlify seems to have edge handlers in beta www.netlify.com/products/edge/edge-handlers/

  • @dhaniabelega7159
    @dhaniabelega7159 2 года назад +1

    Thanks for the tutorial. Do you know if it's possible to modify the request object before it reaches the api endpoint? e.g. adding a header to the request object. Calling req.headers.addHeader() does not seem to work. The newly added header isn't visible in the api endpoint.

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      Take a look at this example, it shows different ways to add headers github.com/vercel/examples/blob/main/edge-functions/add-header/pages/_middleware.ts Hope this helps!

    • @dhaniabelega7159
      @dhaniabelega7159 2 года назад

      @@TuomoKankaanpaa Thanks. I'd looked at that earlier. Those examples only add response headers

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      @@dhaniabelega7159 Ok! I haven't tried to change the headers so can't say for sure, but maybe test adding the header you want to change. Would that replace the existing one 🤔

  • @user-oi3gg4rw7y
    @user-oi3gg4rw7y Год назад

    Thank you!

  • @riskitall7421
    @riskitall7421 2 года назад

    Love your accent bro.

  • @b1chler
    @b1chler 2 года назад

    But how does the edge help if I have the data in a db anyway?

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      Depends on your setup, but at least it should help because the request doesn't have to go all the way to the server but it can fetch the data at the edge (assuming your db is accessible through api for example). Other thing that it could help with, as I understood it, is that it can cache the results. So for example if you request a page with certain language, on the first request it will fetch the text in that specific language from the db and save it to cache and next requests will serve the cached version of the site.

  • @muzammilsyed2339
    @muzammilsyed2339 2 года назад

    Your VScode theme?

  • @GabrielParaElPresidente
    @GabrielParaElPresidente 2 года назад

    Video sponsor Microsoft Explorer,
    Wait Edge 😂

  • @chakhmanmohamed9436
    @chakhmanmohamed9436 2 года назад

    I can't understand middlewares at all damn

    • @TuomoKankaanpaa
      @TuomoKankaanpaa  2 года назад

      I have more videos coming up about middleware, hopefully those will help. Stay tuned!

  • @abrarisme
    @abrarisme 2 года назад

    Makes sense and all, but makes it seem like we can just use edge functions for everything. Would definitely have to be selective in what we use I imagine. Important note from the docs: vercel.com/docs/concepts/functions/edge-functions
    "The maximum duration for an Edge Function execution is 30 seconds, but the function needs to return a response in less than 1.5 seconds, otherwise the request will time out."