Check out a free preview of the full Deno First Look course
The "Deploying an Oak Application" Lesson is part of the full, Deno First Look course featured in this preview video. Here's what you'd learn in this lesson:
Burke demonstrates how to deploy the simple Oak server by bundling the application with Deno. Deploying using Deno's compile method is also covered in this segment.
Transcript from the "Deploying an Oak Application" Lesson
[00:00:00]
>> So, so far we've built this Oak application. And now what we want to do is we want to deploy this application to production. So that's what we're going to do next. We're actually going to deploy this and watch it run somewhere and talk about the different ways that you can deploy a deno application.
[00:00:22]
So let's switch over to the, let's see here. You know what, let's just stay right here and go wild west out. We'll just figure it out as we go. Okay, when we talk about deploying a Deno application, I think we talked before about the fact that the Deno really wants to have a single executable that you can just deploy and run in the future.
[00:00:54]
And actually that arrived a few days ago actually last week, I think with version 1.6. Now unfortunately, it doesn't work for our project. And I'll show you why. Actually let me back up and talk about the other option. Deno has this built in bundle. So what we can do is we can run.
[00:01:13]
Deno bundle. We have to pass unstable, because it's unstable, and we can create a bundle for our app.ts file. And what it's going to do is it's going to run through and take all of our code and bundle it into a single JavaScript file called bundle.js, which is here.
[00:01:33]
Now the problem is like we could scroll through this and you'll see here's all of our code. This includes Oak and includes all of our dependencies. But the problem is that and it's a long file. At the time that I made this project and recorded this, there seems to be a bit of a problem with.
[00:01:53]
There seems to be a bit of a problem with the way that Denos bundler works, so we actually try to run this. We just say deno run bundle.js, I think that's all we have to do. We get this error, which says there's no middleware to process requests. And that's, because the code is out of order in the bundle.
[00:02:17]
And so I opened an issue on the Deno repo about this. And it's just an issue they're gonna have to fix it. But right now code is being bundled out of order. And because of that, the compiler is also going to throw an error, because it's going to bundle out of order too.
[00:02:34]
So to actually see this work, what I want to do is just revert back to something that's kind of a little bit more simple. So let's go back to our let's do what was like a simple oak server, because that should work to get to the very bottom.
[00:02:50]
Yep, here we go. And let's just kick out all the changes. Yeah, it's fun. Should be left with just the essential stuff. Are app.ts, let's go to solution should be done. There we go. Alright, so, because this is one single file, right? This was our very simple Oak application we should be able to bundle this.
[00:03:17]
All right, so let's just bundle this and see what happens. So I'm going to go to solution here. And then let's just do Deno bundle again. And we're just going to create a bundle. And that should show up in our solution folder. There it is, and now we should be able to run this deno run -A bundle.js, and it works.
[00:03:46]
Okay, so we have a single JavaScript file that we could deploy, and this should work. Theoretically it would work. It does work okay, now, I mean, this is just remarkable stuff, but check this out. Watch this. We can do this. We can do Deno, compile unstable app.ts. And now we have this file here called app and we can run it like this.
[00:04:22]
Okay? Now what's really interesting about that is that I never use Deno. Where's Dino? It's in. That's a compiled executable and Deno is in that executable, which means that all we would have to do to make this thing work is actually deploy this executable, it includes the runtime.
[00:04:39]
It includes everything, which is kind of what the dream of Deno has been about, since the beginning, which I find completely fascinating. Now what's even more interesting here is that, let me I'm going to open this in Windows. So lets here, can I reopen folder in Windows. These composite compiled files are not cross platform.
[00:05:04]
So we try to run this from PowerShell. So let's go to the solution folder. If we try to run this, it doesn't know what to do. It's like I don't know what that is. But if we were to run the compilation step here. I have to provide the unstable flag.
[00:05:26]
All right? Now we've compiled on Windows and now, it works. Right? So we can compile for Linux or we can compile for Windows and get a single executable out the end that will allow us to deploy our server. Because we can't bundle and we can't compile our project and I want to show you what it looks like to.
[00:05:53]
Deploy a full on project like we've been building. We're not going to use the bundle or compilation steps to do that. But I did wanna show you that it was possible. So let's go back to, Open, we reopen this into WSL. And I wanna go back to our Oak application that we were working on, which is our Oak simple server.
[00:06:18]
Is it still there?, I feel like I kicked out a bunch of files. Yeah, I did. I kicked out too much stuff. So let's go over to deploying the application.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops