Adding dynamic content tutorial to existing project

I want to generate page content based on a url like mysite.com/p/username, where that link would show a profile.

I think this tutorial would be helpful but I’m not sure how to add that to an existing project. If my current multi page app has HTML files in the root directory, how do I implement the tutorial? What does my netlify.toml look like in my case?

Also, what does event.path.replace(/\/\.netlify\/functions\/[^/]*\//, '') mean? I know about the replace function in javascript generally, but I’ve only used it for very simple regex.

My netlify instance is genderev.com, it’s not very helpful for this post though.

Hi @askthings, there are many ways to do this, depending on what you’re trying to do. If you use an SPA like React or Vue then you don’t need a lambda function to dynamically change content. The client-side router can intercept URL requests to dynamic pages and then use javascript to change page content. There isn’t a single way of doing this.

If all your asking is how to proxy a netlify function, then you can do this using a .redirects or netlify.toml, as per our docs: https://docs.netlify.com/routing/redirects/

This is what a .redirects rule would look like:

/p/:user /.netlify/functions/user/:user 200!

That would also pass the user in to the function as part of the path. You can also add it as a query param or something similar if you prefer.

Hi, can I ask if you mean _redirects or .redirects? The doc you linked to refers to the file in question as _redirects. Thanks!

Also, I tried creating a user.html file in the path /.netlify/functions/user where user.html is the user. I knew this probably woudn’t work but I don’t know what to do.

The tutorial I first linked to isn’t working for me because I need to generate HTML from a Javascript function on the page. I don’t know how to embed a Javascript function in a template literal and when I looked it up it was quite complicated. I am not using a SPA.

Hey @askthings,
_redirects, with the underscore, is the name of the file :slight_smile:

Here’s a good blog post introducing Netlify functions (with Express.js), which are AWS lambda functions under the hood:


This may be a good place to start if you’re familiar with a REST-style server setup? With Netlify, there’s no server at runtime, so you can’t send and receive data back and forth out-of-the-box but with functions, you can make something that feels like that.

That said, if you want to store user’s profile data so they can see their same profile every time they visit and log in, then you’ll need a database. Here’s a demo repo for setting up FaunaDB with Netlify:

Let us know if we can help with anything else!