I have an already running website which frontend is made with React and a nodeJS/Express backend.
What I'm trying to accomplish now is to offer an RSS feed, but I don't know how to approach this.
I've found some ways to generate the RSS feed file (XML I suppose) in the backend, but then I'm not sure how to make it available in the frontend since it's a React one, in my server configuration (NGINX) every URL is redirected to the root and React takes care of routing. That's why I don't know how to make the RSS available in the frontend.
Also, I'm not sure what's the URL "convention" for serving RSS feed. I've seen some URLs with the protocol feed:// or ending in /rss too.
In the webpage we have some categories, so we'll have RSS for each of them, not just the root.
Any help on how to approach this problem will be more than welcome.
Thank you so much!
I finally got a way to do what I was looking for. This is what I've done, in case someone faces the same issues and can find this helpful.
I've added a new location in my NGINX configuration file:
location ~ ^[\/](?<tag>.*)[\/](feed) {
proxy_pass http://localhost:4000/feed/$tag;
}
The regex in that location is going to match any URL that contains /feed at the end of it and it's going to store in the variable tag the string of the "category" that I want to send to the backend to render the RSS feed.
So, for example, this will match: https://mywebpage.com/category/feed and it will store category in the variable tag.
With this done, just need to make the /feed endpoint available at the nodeJS/Express backend side.
Related
I have existing app that runs on Heroku. It's a simple web app with no background jobs or database.
Basically it has three endpoints. One of them serves the HTML, the other is POST endpoint for communicating with backend and third is GET endpoint that renders error HTML content as well.
Now the frontend is not single page application and the goal is not to be one. It's just HTML page with a form and some links. The front end can be used without Javascript.
My questions are:
Can I re-use existing ExpressJS code? I was thinking about importing route callbacks and use them inside the "functions".
I know there is Firebase hosting that can serve static content. However, as I mentioned the server can respond with HTML content so I'd need traditional routing (such as /error url for rendering HTML error). In my ExpressJS app I use .ejs templating so I'd like to load the template and render it.
Can Firebase be set up so the "backend" (functions) can be placed on my own domain? I'd like to call relative URLs from my index file (like that POST endpoint) instead of using Google Firebase URL.
I'm really just trying to find out if my use case can fit the Firebase infrastructure. I think it's a good candidate since I need the web app to respond infrequently and it's not really demanding, not many people would use it. This is also my hobby project so I'm trying to minimize costs.
To answer your questions:
Yes you can, but keep in mind some things are limited. In my case, I had tried to use multer library for multipart forms but didn't work and had to resort to using busboy instead. To use an Express app for a function endpoint, you simply just pass your app as the onRequest function parameter like so: functions.https.onRequest(app).
Docs:
https://firebase.google.com/docs/functions/http-events#using_existing_express_apps
The hosting is for static files only. You can't use that with .ejs. Unless, you're thinking to use that as a proxy to your Express app..
Yes, you can set custom domains so you can use your domain(s) instead of default ones. Reference: https://firebase.google.com/docs/hosting/custom-domain
From your project's Hosting page, enter the wizard for connecting a custom domain:
If you have only one Hosting site, click Connect domain.
If you have more than one Hosting site, click View for the desired site, then click Connect domain.
Enter the custom domain name that you'd like to connect to your Hosting site.
(Optional) Check the box to redirect all requests on the custom domain
to a second specified domain (such that yourdomain.com and
www.yourdomain.com redirect to the same content).
Click Continue to initiate the validation process.
Being new to WordPress, I've been doing some research and yet I don't seem to be able to pinpoint a solution for my need.
In short, I would like to allow a WordPress page to access a Node.js backend, the goal is ultimatly to get access to MongoDB via Node.js, retrieve some data and return a dynamically generated webpage to the website.
I was checking WordPress Rest API but all it seems to do is frontend handling of a WordPress website, creating and editing post, etc.
Unless there's a better way of doing it, I was thinking I might just send a get/post request from the WP page (like, with a form's action) and use Express.js to listen to that request, do the whole workflow on Node.js, then maybe use some npm wordpress API (like this one) to create a wordpress client and add a page or post with the DB extracted content.
I would appreciate some guidance, if any, as to how could one connect from WordPress to a Node.js backend.
Thanks a bunch!
There are a lot of ways to do it.
If you only need Node for a particular page then you can use your web server (NGINX/Apache) to reverse proxy a particular path to the Node server.
If you had to you could always use an HTML iframe as well but for some reason I feel like that's bad advise.
The method you described would work too. I was considering using GET/POST requests with Express running on a different port for a project I'm working on that uses Wordpress. I decided to go with the solution linked below.
This is probably the method you're looking for based on your description. Skip to solution three if you have to use Wordpress.
Node JS Reverse Proxy (with Apache)
You can find how to do it with NGINX with a quick search.
I've been studying to use angular2 following the official tutorial -- "tour of heroes". I know that it directs all url paths to the root '/' so that index.html in the root directory can get the path info for angular router. While I noticed that it also rewrites the url path for APIs on the back-end, such as using "get( 'app/heroes/id')" to get data from the API. What confused me is how does angular2 or node.js achieve that? Since the server has directed every path to the root, then how does front-end side make request to the APIs on back-end, I don't understand why there is no conflicts in the tutorial while I think there should be. For example, if I make a request to an API on back-end, since url path has been rewritten and directed to the root, then my request will be directed to the root directory too not to the API, am I right? Anyone can teach me the principles behind this in Angular2 please? Thanks in advance!
As most of my content is static i was planning to have nginx to handle the serving of static files. But the static content is also private. Different users have different content.
The application itself is written in node.js/express.js
And i was wondering how i should handle authentication/authorization. Is there anything, any nginx module for this.
Something like node.js put some token in memcached which nginx looks up upon request or something like that?
Yes, there is such a feature, checkout the following more detailed articles:
http://wiki.nginx.org/XSendfile
http://kovyrin.net/2006/11/01/nginx-x-accel-redirect-php-rails/
All you have to do is to make a Node.js send the path of the file to NGiNX by setting the header "X-Accel-Redirect" with the location of that file.
I've got a CouchDB server up and running serving basic API requests. Overall it works well because users can GET/POST/PUT etc. to the host 'api.example.com'. The only issue is that if a user does a GET request for '/', they get the {"couchdb":"Welcome","version":"1.0.2"}.
Is there anyway to serve a single static HTML page or even an HTTP redirect for the root? That way I could redirect users to the API documentation.
I'm vaguely familiar with Couchapp but it seems like overkill for such a simple task.
Thanks!
You probably want a vhost/rewrite rule. They are pretty easy. Basically you tell CouchDB that queries to "www.example.com" should go directly to the rewriter. The rewriter will serve anything that you specify in the design document.
Jan Lehnardt wrote up good instructions in the Couchbase blog post, Nice URLs.