Displaying a login-screen is one thing, but it doesn’t help us all that much if we can’t process the user’s input, right?! Let’s add this feature now!
First, we need to install another package that allows us to extract data from POST-requests:
|
|
We need to include the body-parser in our server.js
so we can use it:
|
|
With this in place we can add yet another routing-rule in our server.js
:
|
|
What are we doing here? We’re telling express to listen for POST-requests to localhost:8080/login. From the body of those requests we’re extracting ‘username’ and ‘password’ (since that’s what we named our input
-Elements in login.html
). Check out your console to see both of them displayed there. Then we’re redirecting the user to our landing page. We can now process this information however we like. Proper authentication would be nice, right? Don’t worry, we’ll get to that in a little bit!