loading...

Discussion on: User Authentication with Next.js

Collapse
jolvera profile image
Juan Olvera Author

Hey Mustafa!

Let's clarify some points before the explanation.

The application in the example is built as a monorepo and it's meant to be deployed at Now.

The files that are in the api/ folder compose the backend. The files inside the www/ folder are the frontend, in this case, the Next.js application.

In the backend, every file it's a single function and works as an API endpoint. They are serverless lambdas, you can think of them as a route in an Express.js application, but this is an oversimplification.

So, the Micro package contains utilities that make it easier to deploy this kind of applications.

For example, if I need to parse JSON, with Express.js I'd have to include the entire library, setup middlewares, and so on. With Micro we can use a function from the package and pass the request as a parameter, e.g.,

// example.js

const { json } = require('micro');

const fn = (req, res) => json(req);

modules.export = fn;

so, if we save this code into a file called example.js we can deploy it to Now along with a now.json file and get a functional endpoint that we can call with fetch or axios.

You can clone the example repo and deploy it following its instructions. Once you see it working, take a look at the code, at the logs in Now and you will get a better idea of how it works.

Ping me on Twitter at @_jolvera if you have more questions and we can chat about it.

I hope this helps!

Collapse
stokescomp profile image
Michael Stokes

Your link to monorepo doesn't exist.

Thread Thread
jolvera profile image
Juan Olvera Author

Hey, Michael.

ZEIT changed their repos. The replacement for the monorepo is gatsby-functions.

Collapse
mustafaalfar profile image
mustafa-alfar

thank you for this elaborating,
I'll try it out, and I'll tell you if I struggled with something.