Simple Ruby rack app. Load all subfolders - html

I am trying to create simple rack app with static pages.
The structure of my app:
public
|-index.html
|-css
|-skins
|-blue
|-blue.css
|-yellow
|-yellow.css
....many more...
|-js
|-bootstrap
|-aide
|-abide.js
...many more...
config.ru
Gemfile
My config.ru file
use Rack::Static,
:urls => ["/images", "/js", "/css"],
:root => "public"
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
]
}
The problem is that inside each folder "js", "css" I have hundreds of subdirectories and files and don't what to specify them manually. Can I load all subfoldres at once?
EDIT
With above configuration, when I ran rackup and pointed browser to localhost:9292. I ve just seen white screen loading. I thought that problem could be that subdirectories aren't loaded. But after I ve looked into log I found that my assets are being loaded in infinite loop and that's why app doesn't respond.
like
127.0.0.1 - - [24/Jan/2014 14:35:01] "GET /js/gmap3.min.js?_=1390559355618 HTTP/1.1" 200 29735 0.0015
127.0.0.1 - - [24/Jan/2014 14:35:01] "GET /js/waypoints.min.js?_=1390559355619 HTTP/1.1" 200 8044 0.0012
127.0.0.1 - - [24/Jan/2014 14:35:01] "GET /js/bootstrap/tab.js?_=1390559355620 HTTP/1.1" 200 3420 0.0009
All assets are loaded with 200 success status. I don't have any additional specific configurations. Gemfile is
source 'https://rubygems.org'
gem 'mail'
gem 'rack'

A correct index.html source could be a solution.
To debug what is happening, you can try to load your index.html with only one specific JS/Css file and temporary comment in all others to make sure you don't repeats you self.
Hope it helps.

Related

ERROR `/' not found. ERROR `/blog/assets/main.css' not found.

Noob here. Recently setup jekyll with github pages and the site is functioning on the github server however, since i pushed to github I am now having problems when I enter jekyll serve in to the shell and make any changes in my blog posts md files. The following message appears in the command line and a 404 page not found on my local server... All I did was add some content to one of my posts.. Didn't change any front matter either, have since undone any changes and still i get the same error...
tim#ubuntu16:~/github/blog$ jekyll serve
Configuration file: /home/tim/github/blog/_config.yml
Source: /home/tim/github/blog
Destination: /home/tim/github/blog/_site
Incremental build: disabled. Enable with --incremental
Generating...
done in 0.199 seconds.
Auto-regeneration: enabled for '/home/tim/github/blog'
Server address: http://127.0.0.1:4000blog/
Server running... press ctrl-c to stop.
[2018-04-08 21:56:21] ERROR/' not found.
[2018-04-08 21:56:21] ERROR /blog/assets/main.css' not found.
[2018-04-08 21:56:21] ERROR/blog/assets/minima-social-icons.svg' not found.
`
`
This is where it breaks : "Server address: http://127.0.0.1:4000blog/"
In _config.yml, set baseurl: /blog

Server unable to find JSON files, but finds IMG files in the same Assets folder

I have built a portfolio site for my first Angular project and now it is ready and I'm getting an error when my Angular project attempts to locate the JSON files, but it can find and generate the image files that are in the same assets folder and I can get the JSON when I run my project locally-
main.dad43c6….bundle.js:1 ERROR
e {headers: t, status: 404, statusText: "Not Found", url: "http://megakyle83.com/assets/json/socialMedia.json", ok: false, …}
error
:
"<HTML>
↵<HEAD>
↵<TITLE>404 Not Found</TITLE>
↵<BASE href="/error_docs/"><!--[if lte IE 6]></BASE><![endif]-->
↵</HEAD>
↵<BODY>
↵<H1>Not Found</H1>
↵The requested document was not found on this server.
↵<P>
↵<HR>
↵<ADDRESS>
↵Web Server at megakyle83.com
↵</ADDRESS>
↵</BODY>
↵</HTML>
headers
:
t {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message
:
"Http failure response for http://megakyle83.com/assets/json/socialMedia.json: 404 Not Found"
name
:
"HttpErrorResponse"
ok
:
false
status
:
404
statusText
:
"Not Found"
url
:
"http://megakyle83.com/assets/json/socialMedia.json"
__proto__
:
Object
When I did my build I used the terminal command ng build --prod and then uploaded the files from the generated dist folder onto my Windows Plesk Server through GoDaddy. When I look at my assets folder on the Plesk server it shows that all the files are there under assets/json/ . I have several separate JSON files in this same folder. Could that be part of the problem?
I have all my files uploaded to my github at -https://github.com/RyanIndustries8/megakyle83
I have tried everything under the sun to make this work and I'm struggling to find anyone who knows enough about Angular to get an answers.
Look at the error message, http://megakyle83.com/assets/json/socialMedia.json 404 Not Found. I've browsed your repo and there is no such a file in assets/json/ directory moreover, there is no json directory in the assets.
I couldn't find missing socialMedia.json file in your entire repo. Ensure that this file exist under path mentioned in the error message.
The issue didn't end up being my code, instead it was a setting issue in the Plesk Server. I had to go into the Server Settings and add text/json and */json to the list of usable files. Thank you for looking at this issue.

Jekyll bad uri bad request line

For some reason I started getting this error and I'm not sure why. I haven't been doing anything differently, it just started doing this. Does anyone know why this would be happening?
Bryans-MacBook-Pro:website bryan$ bundle exec jekyll serve
Configuration file: /Users/bryan/Dropbox/Websites/Clients/website/_config.yml
Configuration file: /Users/bryan/Dropbox/Websites/Clients/website/_config.yml
Source: /Users/bryan/Dropbox/Websites/Clients/website
Destination: /Users/bryan/Dropbox/Websites/Clients/website/_site
Incremental build: disabled. Enable with --incremental
Generating...
done in 0.114 seconds.
Auto-regeneration: enabled for '/Users/bryan/Dropbox/Websites/Clients/website'
Configuration file: /Users/bryan/Dropbox/Websites/Clients/website/_config.yml
Server address: http://127.0.0.1:4000/
Server running... press ctrl-c to stop.
[2017-10-31 11:06:45] ERROR bad URI `d??\x1EG?7?\x16??\x06???\x16????\\,?\x01\b?oq?K\x00\x00(?,?+?$?#?'.
[2017-10-31 11:06:50] ERROR bad Request-Line `\x16\x03\x01\x00?\x01\x00\x00?\x03\x03\x14?????.?z?m??\x02®?,??("p?M%?'\x17?N\x00\x00.?,?+?$?#?'.
[2017-10-31 11:06:50] ERROR bad Request-Line `\x16\x03\x01\x00?\x01\x00\x00?\x03\x01????ۙ\x10o?/?\\????k?<r\x18ofGL>`\x02?Ć\v\x00\x00\x12\x00/\x003\x005\x009?\t?'.
If you are receiving this answer it is because your browser is trying to load the page via https and not http

How to serve images with nginx

I am completely new to nginx and I am asked to find a way to serve Map Tiles that are separated according to the zoom levels. The image file structure is like ~/data/images/7/65/70.png where 7 is the zoom level, 65 and 70 are the lon-lat values. The folder 65 contains many files such as 71.png, 72.png and etc.
I have installed Nginx properly and I can get Welcome to nginx message. I have followed the instructions in http://nginx.org/en/docs/beginners_guide.html and created the /data/www and /data/images directories. I have placed index.html file under /data/www and tile images under /data/images. Then I modified the configuration file by adding following lines in http tags:
server {
location / {
root /data/www;
}
location /images/ {
root /data;
}
}
After reloading the config file and entering localhost on the browser I can neither get the index.html file nor see the images.
What I am trying to do is to display the image when I enter something as:
http://localhost/1.0.0/basemap/7/65/70.png
7: folder indicating 7th zoom level
65: folder indicating the latitude
70.png: file indicating the longitude (folder 65 includes many png files)
What am I missing?
Ok, let me explain something, you already have a localhost server, which is defined inside a file called default that is the file that causes the "Welcome to nginx" or something to appear, and I believe you can't create a new server with the same server_name, let's remove that and make your localhost serve only those images,
First we need to delete the default file from sites-enabled , it will still exist inside sites-available if you ever want to get it back. ( note that all files inside sites-enabled are simply symlinks from the files inside sites-available )
We create a new file inside sites-available and call it whatever you want, images-app for example
create the new server inside the images-app file, I'll assume that the root of the app is inside a folder called /data of course you will map that to your own server structure.
server {
server_name localhost;
root /data;
index index.html;
location / {
try_files $uri =404;
}
}
now we go to sites-enabled and enable this site we created inside sites-available
sudo ln -s /etc/nginx/sites-available/images-app /etc/nginx/sites-enabled/
make sure that all the nginx config are correct
sudo nginx -t
If nothing is wrong we can go ahead and reload nginx settings
sudo service nginx reload
For my case I just edited /etc/nginx/sites-enabled/default file.
I added following config:
location /images/ {
root /data;
}
and placed images under /data/images:
and url works: http://localhost/images/example.png
I use VS Code as SuperUser. (I know it is bad, but I accept risks)
It helps a lot with root access file editing:
I'm also new to nginx, Here is my solution that is similar with Mohammad AbuShady's answer :
delete sites-enabled/default
create the whatever.conf in /etc/nginx/conf.d/
The reason is:
sites-enabled/default has defined a server
that is listening on 80 rooting with /var/www/html
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
the nginx.conf file includes other conf files
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
pay attention on permission
the 1st edition of my.conf is root on /home/scotv/, but will get 403 Forbidden error, check the error.log:
2016/04/07 20:12:44 [error] 12466#0: *2 open() "/home/scotv/data/a" failed (13: Permission denied),
client: 127.0.0.1, server: , request: "GET /a HTTP/1.1", host: "localhost"

LiveReload Chrome Extention unable to connect to Guard server on Ubuntu 13.04 64bit

I have installed the necessary gems as follows :
~/Desktop/html5$ gem list
bundle (0.0.1)
bundler (1.3.5)
coderay (1.0.9)
em-websocket (0.5.0)
eventmachine (1.0.3)
ffi (1.8.1)
formatador (0.2.4)
guard (1.8.0)
guard-livereload (1.4.0)
guard-sass (1.2.0)
This is what my Guardfile looks like :
~/Desktop/html5$ more Guardfile
A sample Guardfile
More info at https://github.com/guard/guard#readme
guard 'livereload' do
watch(%r{.+\.(css|js|html)$})
end
This is what I get when I run : bundle exec guard
~/Desktop/html5$ bundle exec guard
12:05:56 - INFO - Guard uses NotifySend to send notifications.
12:05:56 - INFO - Guard uses TerminalTitle to send notifications.
12:05:56 - INFO - LiveReload is waiting for a browser to connect.
12:05:56 - INFO - Guard is now watching at '/home/praveen/Desktop/html5'
[1] guard(main)>
To make sure the Guard server is running , this is what i get when telneting
:~/Desktop/html5$ telnet 127.0.0.1 35729
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
When I make changes to the index.html in the monitored directory , this is what i get at the guard prompt
13:36:20 - INFO - Browser connected.
13:36:25 - INFO - Reloading browser: index.html
13:36:34 - INFO - Reloading browser: index.html
[1] guard(main)>
I have installed the chrome live reload plugin and given it file reading permission but when I click it , it doesn't change and thus does not reload the code change to any html or css in the /home/praveen/Desktop/html5 , pls let me know what can be done.
Praveen
After Struggling for 2 days , this is the method that I figured to work without hassle on Ubuntu 13.04, it has thus made my workflow seamless :
Install LiveReload from Through Python and CD to the directory that needs to be watched for changes
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
pip install livereload
sudo apt-get install python-pip
pip install livereload
cd FolderToBeMonitored/
Create a file called Guardfile with the following contents to monitor for all changes to html and css files
Desktop/html5$ more Guardfile
#!/usr/bin/env python
from livereload.task import Task
Task.add('*.css')
Task.add('*.html')
Task.add('css/*.css')
praveen#praveen-XPS-L412Z:~/Desktop/html5$
Once the above is done , start the LiveReload with the below command :
livereload -b
Please note that liveReload uses 35729 as the default port but if it needs to be changed TO 1717 use
livereload -p 1717 -b
The default html file will launch automatically in the default browser , no need to install any buggy chrome extensions . to launch a particular file , use appropriate URL of the below format
http://127.0.0.1:35729/test.html
I prefer this way the Ruby gem installation followed by the chrome extension that needs to connect to the port method, I spent 2 days on this issue and it never worked until figuring out the above methodology that works without any chrome plugins.
I managed to make it working using this as guard file
I have Ubuntu 13.04 raringtail
# This will concatenate the javascript files specified in :files to public/js/all.js
guard :concat, type: "js", files: %w(), input_dir: "public/js", output: "public/js/all"
guard :concat, type: "css", files: %w(), input_dir: "public/css", output: "public/css/all"
guard 'livereload' do
watch(%r{/.+\.(css|html|js)$})
end
guard 'sass', :input => 'sass', :output => 'css'
The output is this in the terminal:
*dany#dany:/var/www/tucan$ guard
21:07:04 - INFO - Guard is using NotifySend to send notifications.
21:07:04 - INFO - Guard is using TerminalTitle to send notifications.
21:07:04 - INFO - LiveReload is waiting for a browser to connect.
21:07:04 - INFO - Guard is now watching at '/var/www/tucan'
[1] guard(main)> 21:07:23 - INFO - Browser connected.
21:07:23 - INFO - Browser connected.
*
Hope this helps someone