404 GET / When index.html is available - crystal-lang

I'm trying to write a simple static site in Crystal using Kemal.
Going by this page, I should be fine, but I get a 404 when I try to load the site.
My program looks like this (you can see all the code I commented out trying to track the issue down)
#require "./LiedThisWeek/*"
require "kemal"
#module LiedThisWeek
# TODO Put your code here
#end
#finder = LieFinder.new
#handler = HyperTextHandler.new finder
#indexPath = "public/index.html"
#
#spawn do
# loop do
# finder.refresh
# File.write indexPath, handler.getDoc
# sleep 60.second
# end
#end
Kemal.run
This is what my directory structure looks like:
.
├── LICENSE
├── LiedThisWeek
├── README.md
├── lib (removed for brevity)
├── public
│   ├── css
│   │   └── style.css
│   ├── images
│   │   ├── fireworks.jpg
│   │   └── sad.jpg
│   └── index.html
├── shard.lock
├── shard.yml
├── spec
│   ├── LiedThisWeek_spec.cr
│   └── spec_helper.cr
└── src
├── LiedThisWeek
│   ├── HyperTextHandler.cr
│   ├── Lie.cr
│   ├── LieFinder.cr
│   └── version.cr
└── LiedThisWeek.cr
32 directories, 112 files

Kemal author here.
Kemal doesn't serve index.html as / by default. However you can achieve that with a redirect
get "/" do |env|
env.redirect "index.html"
end

Related

Gunicorn Nginx Django static files: images not shown

I've been digging through articles and posts about this subject but can't seem to get my images to load. For some reason the CSS on my pages seems to load just fine.
settings.py
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
also I tried
STATIC_ROOT = '/var/www/myname/'
template
<img src="{% static 'picture.jpg' %}" class="img-fluid">
NGINX
/etc/nginx/sites-enabled/django_project
server {
listen 80;
server_name mywebsite.com;
location /static/ {
alias /var/www/myname/static/;
}
}
directories
/var/www/myname
└── static
└── admin
├── css
│   ├── styles1.css
│   └── styles2.css
├── images
│   ├── picture.jpg
│   └── python.jpg
└── js
└── scripts.js
/home/myname/myprojectdir
├── django_project
│   ├── django_project
│   │   └── __pycache__
│   ├── etc
│   ├── index
│   │   ├── migrations
│   │   │   └── __pycache__
│   │   ├── __pycache__
│   │   └── templates
│   │   └── index
│   │   └── backups
│   ├── __pycache__
│   └── static
│   ├── admin
│   │   ├── css
│   │   │   └── vendor
│   │   │   └── select2
│   │   ├── fonts
│   │   ├── images
│   │   │   └── gis
│   │   ├── img
│   │   │   └── gis
│   │   └── js
│   │   ├── admin
│   │   └── vendor
│   │   ├── jquery
│   │   ├── select2
│   │   │   └── i18n
│   │   └── xregexp
│   ├── images
│   └── index
│   ├── css
│   ├── images
│   └── js
├── myname_env
│   ├── bin
│   └── lib
│   └── python3.10
│   └── site-packages
└── static
└── admin
├── css
│   └── vendor
│   └── select2
├── fonts
├── img
│   └── gis
└── js
├── admin
└── vendor
├── jquery
├── select2
│   └── i18n
└── xregexp
I've tried installing the static files in other directories, etc, to see what works but I'm not having any luck whatsoever. I had the static files in the project but after reading that's not a good practice I put them into var/www.
can you add this into nginx conf and try:
location /images/ {
alias /var/www/myname/static/images;
}

match everything besides one folder - regex

I'm trying to exclude files form being watched besides folder app in watchOptions in ESLint.
My folder structure looks like:
├── assets
│   ├── assets
│   │   └── fonts
│   │   ├── FeatherIcons
│   │   ├── Icomoon
│   │   └── Montserrat
│   ├── images
│   ├── imagesNotOptimized
│   ├── js
│   │   ├── app
│   │   │   ├── api
│   │   │   │   ├── erpFlex
I would like to include all the files inside app but ignore all other files.
config.watchOptions = {
poll: true,
ignored: [
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, 'assets/js/*!(app)'),
]
};
I have tried the following regexes
assets/js/*(!app)
assets/js/(?!app)
Nothing seems to work. Any help would be much appreciated. Thank you
EDIT
I have been able to match the string using the following regex: https://regex101.com/r/hs4lOt/1
but path.resolve(__dirname, 'assets/js/(?!app).*') is not working which makes this question not about regex but why ignored is not working in watchOptions

How I could include external lib in my custom opencart extension?

I'm building a custom opencart payment extension (ocmod installable), I need to use an external payment provider sdk (located in the vendor folder) but i don't know how include this files on my packaged extension
This is my folder structure
..
├── install.xml
└── upload
├── admin
├── catalog
├── composer.json
├── image
└── vendor
To develop a payment extention for opencart, follow this structure
admin
│   ├── controller
│   │   ├── payment
│   │   │   ├── custom_payment.php
language
│   │   └── en-GB
│   │   ├── payment
│   │   │   ├── custom_payment.php
template
├── payment
│   ├── custom_payment.tpl
catalog/
├── controller
│   ├── payment
│   │   ├── custom_payment.php
├── language
│   └── en-GB
│   ├── payment
│   │   ├── custom_payment.php
├── model
│   ├── payment
│   │   ├── custom_payment.php
└── view
└── theme
├── default / your_theme
│   └── template
├── payment
│   ├── custom_payment.tpl

Override django userena views

I know there is a plethora of questions related to this, like this one, but I does not seem to help.
My question is simple, given this function signature, how do I override the view profile_detail? I seem to be doing everything exactly as both resources say, but my templates are still not receiving the extra context. Here's what I am trying to do:
# This overrides and extends userena's view named 'profile_detail'.
def profileDetailView(request, username):
# Do some logic, etc.
foo_list = Some.objects.filter(id=username)
extra_context = {'foo_list': foo_list}
# I have also tried the following for extra_context:
extra_context['foo_list'] = foo_list
return userena_views.profile_detail(request, username, template_name='userena/profile_detail.html',
extra_context=extra_context)
I am not sure where I am going wrong. I have my URL's correct, as it is loading my views without error. Also, I have tested through the shell to create foo_list by import objects - it worked. I have also done a test to make sure the username being passed in actually results in an object being found. Thus - it seems like the only problem could be in the extra_context, at least I hope! Any help would be much appreciated!
EDIT: File structure Request
├── project
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── static
│   │   ├── css
│   │   │   └─
│   │   └── js
│   ├── test.py
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── manage.py
├── media
├── templates
│   ├── admin
│   │   └── base_site.html
│   ├── base_site.html
│   ├── errors
│   │   └── not_authorized.html
│   └── userena
│   ├── base.html
│   ├── base_userena.html
│   ├── profile_detail.html
│   ├── profile_details.html
│   └── signup_form.html
└── utils
TEMPLATE_DIRS = (
'/home/username/project/project/templates',
)

django, compressor and foundation scss

Hi I am trying to integrate foundation scss into django using django-compressor's precompiler, the project looks like this:
├── manage.py
├── requirements.txt
├── static
│   ├── config.rb
│   ├── humans.txt
│   ├── index.html
│   ├── javascripts
│   │   ├── foundation
│   │   │   ├── foundation.alerts.js
│   │   │   ├── foundation.clearing.js
│   │   │   ├── foundation.cookie.js
│   │   │   ├── foundation.dropdown.js
│   │   │   ├── foundation.forms.js
│   │   │   ├── foundation.joyride.js
│   │   │   ├── foundation.js
│   │   │   ├── foundation.magellan.js
│   │   │   ├── foundation.orbit.js
│   │   │   ├── foundation.placeholder.js
│   │   │   ├── foundation.reveal.js
│   │   │   ├── foundation.section.js
│   │   │   ├── foundation.tooltips.js
│   │   │   └── foundation.topbar.js
│   │   └── vendor
│   │   ├── custom.modernizr.js
│   │   ├── jquery.js
│   │   └── zepto.js
│   ├── MIT-LICENSE.txt
│   ├── robots.txt
│   ├── sass
│   │   ├── app.scss
│   │   ├── normalize.scss
│   │   └── _settings.scss
│   └── stylesheets
│   ├── app.css
│   └── normalize.css
├── templates
│   ├── 404.html
│   ├── 500.html
│   ├── admin
│   │   └── base_site.html
│   └── base.html
└── weddings
├── __init__.py
├── __init__.pyc
├── local_settings.py
├── local_settings.pyc
├── settings.py
├── settings.pyc
├── urls.py
├── urls.pyc
└── wsgi.py
and the precompiler looks like this in settings.py
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'sass --scss --compass {infile} {outfile}'),
)
And when I run it with nginx + uwsgi, I get the following error:
Syntax error: File to import not found or unreadable: foundation/foundation-global.
Load paths:
/etc/uwsgi/vassals
/etc/uwsgi/vassals/sass
/srv/www/weddings/gems/compass-0.12.2/frameworks/blueprint/stylesheets
/srv/www/weddings/gems/compass-0.12.2/frameworks/compass/stylesheets
Compass::SpriteImporter
/srv/www/weddings/gems/bourbon-3.1.1/app/assets/stylesheets
/srv/www/weddings/gems/bourbon-3.1.1/app/assets/stylesheets
on line 2 of /srv/www/weddings/weddings/static/sass/_settings.scss
from line 2 of /srv/www/weddings/weddings/static/sass/app.scss
Use --trace for backtrace.
I suspect it's not reading the config.rb or the settings in config.rb is wrong:
http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
As you have a config.rb file, you have a Compass project.
Compass projects are supposed to be compiled with the compass command line tool, not sass command line tool.
As you have already discovered, compilation should be launched from insie the project folder. But it's a bad idea to hardcode the path into settings.py as it makes your project unportable.
Instead of a hardcoded path, you should use os.path.dirname(os.path.realpath(__file__)) to discover current script's path. To change the folder relative to settings.py, use os.path.join() like this (adjust as necessary, you can use ..):
os.path.join(os.path.dirname(os.path.realpath(__file__)), "static")
Also, you may already have PROJECT_DIR var in your settings.py. Use it to make this line cleaner.
A little improvement to #James Lin
COMPRESS_PRECOMPILERS = (
# ('text/x-scss', 'django_libsass.SassCompiler'),
# ('text/x-scss', 'sass --scss {infile} {outfile}'),
('text/x-scss', 'sass --scss --compass {infile} {outfile}'),
)
My current work around is to run the sass command in the folder where ocnfig.rb is located
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'cd /srv/www/project/name/static && sass --scss --compass {infile} {outfile}'),
)