http-server : how to set the root directory of my server? - node.js

I run a server via node's http-server module. Trouble is, it displays the working directory /document/js/ :
# /document/js/server.makefile
node ../node_modules/.bin/forever ../node_modules/.bin/http-server --cors &
# localhost:8080 shows content of /document/js/
I actually want my server to show the content of /document.
How to set the root folder of my server (/document/js/server.makefile) so localhost:8080 displays the content of /document/ ?

The http-server docs usage states that you can pass in a path before your options. So in your case, you might want to try something like:
hs /document [your_options]
Add -o to open your browser after starting your server.

Related

How to set up the root directory for apache2 Server?

Im trying to publish my website for the first time (complete newbie in servers). Im using apache2 and the app is built with node/react/express.
The index.js file is inside myapp/packages/hotel/src.
what I did:
changed the root folder in /000-default.conf to "var/www/html/myapp/packages/hotel/src"
deleted the existing html folder with sudo rm -r html
made the git clone command sudo git clone www.xyz123.. html
When i open the website, there is "index of / " and the directories. The index of doesent even point to the src folder, its still inside the main directory.
What did i miss? It should load the index.js
Re. 1: Use an absolute path:
DocumentRoot /var/www/html/myapp/packages/hotel/src
Re. 3: Use git archive instead of clone as you don't want the .git directory to be served. If your intention was for index.js to be an app that runs on the server, then you want to use node.js instead of apache2 to serve it.

How to serve static files with nginx after using npm run build with webpack

after generating a development build with npm run build i get the message saying
"Tip: built files are meant to be served over an HTTP server.
Opening index.html over file:// won't work."
What is the best way to do this with nginx? Currently to test it i am using an npm module called serve.
Also, if i got to my homepage at mydomain.com and search for a user, everything works like it is supposed to, redirecting me to mydomain.com/users/brad but if i then do a url search formydomain.com/users/brad i get a not found error, any help is appreciated!
In my case, when I have to serve static content with nginx, it often looks like :
location /static {
alias $myroot/staticfiles;
}
Also, if you haven't already, read the NginX guide to Serving Static Content.
If your are familiar with the Docker technology i would recommend to use a Docker Nginx Container and add your static content from the Webpack Buildflow to your container (this can be automated with a build server). Have a look at the following Docker Image from Nginx: https://hub.docker.com/_/nginx/.
Otherwise you have to install nginx on your Server where you host your Homepage. For this have a look at your Server OS and reach out to the web for a detailed nginx setup for your server. Without any configurations nginx will serve the static content on Linux-like server from /usr/share/nginx/html
If you only have FTP Access to your server you can transfer your built files via FTP/SFTP to a specific folder e.g /myHomepage and then your static content is server from yourdomain.de/myHompage.

how to use polymer starter kit doc & demo offline?

i have installed polymer starter kit 1.3.0, Using gulp serve i can access index.html located in app folder at localhost:5000.
i have two questions.
1) My question is how to access pre-developed components located at /bower-components/ on web browser?
i have tried to install and serve gulp in /bower-components/,but it still serve the /app/index/
i am not able to access components references on web browser.
2) After complete development how to host it without gulp, ex. on xampp?
You could use Python's HTTP server to serve up the bower_components directory, allowing you to access the subdirectories offline:
Open a terminal into bower_components/
Run: python -m SimpleHTTPServer 8000 to start an http server on port 8000.
Open a browser to http://localhost:8000/{dir}, where {dir} is the directory name of the component you wish to view (e.g., http://localhost:8000/paper-ripple/).
I think in the starter kit, bower_components directory is mapped to the /components url when you use gulp serve. This is the same url as your app/elements directory.
This is designed so that you app-elements can access polymer by a url of ../polymer/polymer.html (and similarly for the other elements)

How can I use (Node) Livereload on a development server in my network

Background: My PHP projects (CakePHP, Wordpress) run on an Ubuntu server in my network, I access them through a development TLD (.dev for example) setup through a local DNS server and I edit the files through a Samba share.
I would like to utilize Livereload for my development, preferably have it running on the server itself. I have basic Node/Gulp knowledge, but haven't been able to get this running.
Livereload (or a middleware server) should proxy the 'real' URLs, making sure all websites run as they would normally and Livereload should be available over the network (so not just localhost, because that runs on the development server)
Desired result:
Livereload runs on my dev server (IP: 10.0.0.1), my project is called helloworld.dev, I browse to 10.0.0.1:3000 on my machine and see helloworld.dev proxied through Livereload. I now edit a CSS file over the Samba share and the CSS is reloaded without a refresh.
I've tried using a few NPM packages, gulp-livereload, livereload, node-livereload, with their provided examples that come with the packages, but haven't been able to get the desired result. They all expect you to run in locally, don't support access to the Livereload URL over the network, cannot proxy the 'real' URLs or require static content.
Can anyone provide an example or 'proof of concept' code of my wish, so I can see where to start?
I found the answer: http://nitoyon.github.io/livereloadx/
This does EXACTLY what I need.
I can run
livereloadx -y http://helloworld.dev -l
open
http://serverip:35729
and I'm ready to roll.
The -y option creates the proxy to the 'real' URL and the -l makes it serve files from local filesystem instead of through its proxy.

Getting the node.js monitor-dashboard project to work externally

I'm trying to get the monitor-dashboard project to work but i get a page can't be found error when I try to use a browser externally.
http://lorenwest.github.io/monitor-dashboard/
Internally seems OK, I'm getting a HTTP/1.1 200 OK from http://localhost:4200 with the usual curl command.
I went in to node/node_modules/monitor-dashboard/config/, and changed default.js and external.js and changed all occurrences of allowExternalConnections to true.
I've also got node-monitor loaded in to my node project.
I'm running node server.js first and then npm start monitor-dashboard in another window.
port 4200 is open via iptables -L
Any ideas?
The setting you're looking for is:
export NODE_ENV=external

Resources