How to add a new type (.htc) in mongoose - mongoose-web-server

I am creating a CGI based application(using C) in mongoose server. That web application is using for hardware setting. Javascript, CSS, CGI,etc all things is working fine in my mongoose server. Here I want to use ".htc" files in CSS. So How it is possible in mongoose as same as in Apache. In Apache server we can use "AddType text/x-component .htc", line in .htacces files to enable that support. Please let me how it is possible in Mongoose web server.
Thanks in advance

Set extra_mime_types option to .htc=text/x-component

Related

Do I need to make any changes in my node.js codes to deploy it over the web?

I've created a website using html,css,sass,js, node, express & ejs. Do I need to make any changes in the code to deploy it over the web?
P.S. I've set the port to process.env thing and added the css & js files to a public folder. Are there any other changes I need to make?
Not sure what you are asking.
You basically need to make it publicly available.
You could either do it using a host provider or in theory you could set up your own server using apache ,nginx etc then reroute your home router to your machine (laptop).
Your server will run the same way as locally in theory.
You just need something to redirect the traffic in and out.

Connect from WordPress webpage to a Node.js backend server

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.

How to password protect nodejs application using alternative to htaccess

I have a site hosted in aws with www.domain.com with 2 sub domains test.domain.com and stage.domain.com. I am using MEAN for development, now what i want is to password protected my sub domains test.domain.com and stage.domain.com but in a similar fashion as we do in php using htaccess.
Now i personally like this htaccess approach because in this approach your code for the application will be same, authentication will be added by htaccess. Any idea how to do that in nodejs without altering application code, so that i can remove that in future if i want.
P.S. : Only hints are welcomed.
.htaccess does not alter the code because it's used by the Apache webserver.
Consider that Node.js IS your webserver, so that's where the magic happens (technically, it takes less code to add basicAuth to node than to add htaccess to apache + write the .htacess file).
Something, somewhere has to know that authentication is to be done :).
Here's the link to an easy way to do that in node :
Basic HTTP authentication with Node and Express 4

Changing localhost server files are served from using Node (Webstorm /maybe IntelliJ)

I'm not sure what I'm missing here, so hopefully someone can help me out. I'm working on a project where we're using Node and in the Run/Edit configurations I've down the following:
Node interpreter: This is the path to the node.exe file
which I checked out from Subversion
Working directory: this is where the "app.js" file is, this is the
path that from the command line you type node app.js and it starts the server
JavaScript file: app.js This is the name of the file that actually creates the server
Now from the main nav bar when I do Run / Run my server the box at the bottom pops up and tells me that Express server is listening on port 3000. Cool.
I can navigate to localhost:3000/myPage.html and I can get to the page just fine.
I added as JSON file to the same directory on my hard drive that myPage.html is in, and I can navigate to that as well by localhost:3000/largeTestData.json.
So the server is up and running and serving file as it should. My problem is that in my Webstorm project, I want to make an AJAX request to that largeTestData file. I do so using jQuery like:
var data = $.get('localhost:3000/largeTestData.json');
data.done(function(data){
console.log('here is your data');
cnosole.log(data);
})
When I do that I get the error (in Chrome)
XMLHttpRequest cannot load localhost:3000/largeTestData.json. Cross origin requests are only supported for HTTP.
and so I look at the URL and I'm seeing:
http://localhost:63342/
Obviously Webstorm has started the server correctly, but when I view an HTML file, it's not using that server (which, of course is why I'm getting the CORS error.
There's some fundamental stuff here which I'm obviously not getting. I need my IDE to deploy to the Web server that it started up, but it's not doing that. Please, someone give me a once over on all the technologies that I'm missing out on here.
WebStrom didn't start your node.js server, but serves static pages by its own internal HTTP server which doesn't know anything about node.js and Express.
The main problem:
When you start your node.js server, it's serving JSON files on port 3000. If you open an HTML-page with the little menu in WebStorm (where you can choose the browser), WebStorm opens the browser with an URL pointing to its own internal webserver running on a different port (e.g. 63342). JavaScript security prohibits loading data from a different host/port Same-origin policy.
It's not WebStorm's fault and you need a solution for this problem in production or you can't go live.
General Solution:
Either you have to ensure that HTML pages and JSON data come from the same host+port, or you can circumnavigate with (a) setting server-side headers ('Access-Control-Allow-Origin: *') as #lena suggested, or (b) using JSONP. Below you find some thoughts using nginx as a reverse proxy so from browser's point of view all requests go to the same host+proxy. It's a very common solution, but as mentioned above, there are other options.
Primitive solution:
Don't use WebStorm to open your browser. Load the page from http://localhost:3000/ and change the URL of the REST resource to $.get('/largeTestData.json'). You'll miss some comfort from your IDE, but you can immediately see that your program is working.
Comfortable solution:
As #lena suggested, there is a way to configure your Express/node.js as a server known to WebStorm. I haven't tried it, but I suppose you can then just press the Run-button and maybe the node.js plugin in WebStorm is as intelligent to know the static-maps in Express and know how to map an HTML-file to a web application URL and open the page in the browser with the URL served by your node.js application. (I'd be surprised once again if this really works magically, but maybe you can configure a mapping from files to URLs manually, I don't know.)
Dirty solution
With some options you can disable security checks, at least in Google Chrome. Then it's possible to load JSON data from a different port than your HTML page. I wouldn't recommend using these options (just my opinion).
Additional Hints
If you do more than just playing around with node.js and some UI fun and you have to serve your application "production-ready", then have a look at nginx to serve your static files and reverse proxy node.js requests from there. I'm using this setup even for development and it works like a charm.
Of course node.js / Express is able to serve static files as well, but IMO placing something like nginx in front of node.js (clustered) bring a bunch of advantages for production sites, e.g. load-balancing, ssl-offloading, avoid JSONP, in many cases performance, easier deployment updates, availability.
To get your code working, just change the URL in $.get() to full URL (including protocol):
var data = $.get('http://localhost:3000/phones.json');
In Webstorm 2016.3 (and probably earlier) there is now another option. Under the Configuration Settings for NodeJS runs, one can manually set the page and port to be loaded via Webstorm's "Browser/Live Edit" settings.
See the screenshot below for settings one can change.

Adding a node.js applications as an Apache Alias?

When connecting Apache Tomcat web-apps to an existing Apache website, mod_jk can be loaded to give a web application an Alias within Apache.
Are there any similar modules for connecting node.js to Apache?
Node isn't an application server, like Tomcat. It's a native network / web server in its own right (and which runs as its own independent process), so if you want to connect Apache to a Node application, it's easiest simply to use Apache's built-in proxy support.
In most circumstances, it's probably more efficient to have Node act as the web server on its own, as its HTTP support is complete and efficient. There are many web frameworks for it, like Express, Strata or RESTify, and also middleware libraries that handle things like efficiently serving static resources.
Found the answer here and tested it out on my own local webserver.
Just like #othiym23 said you have to use Apache's mod_proxy and mod_rewrite to make it work.
You can add a relatively simple rule to your .htaccess file like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^tiddlywiki5.*$ http://whereNodeDotJSIsRunning:8080/ [P]
</IfModule>
And this will yield a URL like http://yourApacheServer.com/tiddlywiki5/ from which you can visit your node.js server through Apache2. The [P] flag at the end of the rule is used to forward the request to a different server via mod_proxy and return it to the user as though they were visiting http://yourApacheServer.com/tiddlywiki5/
Plesk has an extension for Node now. It's seamless, has wide range of features and free: http://ext.plesk.com/packages/28f799af-1ff4-4bb8-9c87-a04f0f23d32e-jxcore-support

Resources