Use a web server app with Traefik at a given path - traefik

I have a web server app (nginx, html, png...) in a docker container that I can't run correctly with Traefik without 404 files.
All the source files are here to reproduce the test :
.
├── docker-compose.yml
├── Dockerfile
└── www
├── img
│ └── test.png
└── index.html
./www/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
Hello world<br>
<br>
<img src="img/test.png">
</body>
</html>
./Dockerfile
# BUILD: # docker build -t testwww .
FROM nginx:stable-alpine
COPY www /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
docker-compose.yml :
version: '3'
services:
reverse-proxy:
restart: always
image: traefik:v2.4.8
command:
- "--providers.docker"
- "--log.level=DEBUG"
ports:
- "80:80"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
labels:
- "traefik.http.middlewares.mystripprefix.stripprefix.prefixes=/myapp"
myapp:
restart: always
image: testwww
labels:
- "traefik.http.routers.myapproute.rule=PathPrefix(`/myapp`)"
- "traefik.http.routers.myapproute.middlewares=mystripprefix"
When I start with docker-compose up the URL http://localhost/myapp serves the index.html file as expected but the img is 404 (requested at http://localhost/img/test.png). It is 200 OK at http://localhost/myapp/img/test.png.
I tried all I could with replacepath, addprefix, replacepathregex... without success.

If you want to have your picture available at http://localhost/img/croissant.png, you should use:
labels:
- "traefik.http.routers.myapproute.rule=PathPrefix(`/`)"

Related

npm http-server with header X-Content-Type-Options

Used
$ http-server --cors .
to serve the following that tried to access https://github.com/vuejs/vue/blob/dev/dist/vue.js
<!DOCTYPE html>
<html>
</head>
<body>
DEMO
</body>
<script src="https://github.com/vuejs/vue/blob/dev/dist/vue.js"></script>
</html>
However it posted the following error:
The resource from “https://github.com/vuejs/vue/blob/dev/dist/vue.js” was blocked
due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
How to fix it or make npm http-server have header X-Content-Type-Options?

Issue integrating Netlify CMS with my pelican static website (Error: Failed to load config.yml)

I’m trying to integrate Netlify CMS to a static Pelican website.
I can’t seem to access /admin as I get the following error:
Error: Failed to load config.yml
Check your config.yml file.
Here is the content of admin/index.html (I followed these instructions)
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Content Manager</title>
<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
</head>
<body>
<!-- Include the script that builds the page and powers Netlify CMS -->
<script src="https://unpkg.com/netlify-cms#^2.0.0/dist/netlify-cms.js"></script>
</body>
</html>
and here is the content of my config.yaml
backend:
name: github-getaway
branch: master
media_folder: "img/uploads" # Folder where user uploaded files should go
public_folder: "uploads"
collections: # A list of collections the CMS should be able to edit
- name: "post" # Used in routes, ie.: /admin/collections/:slug/edit
label: "Article" # Used in the UI, ie.: "New Post"
folder: "content/news" # The path to the folder where the documents are stored
format: markdown
sort: "date:desc" # Default is title:asc
create: true # Allow users to create new documents in this collection
fields: # The fields each document in this collection have
- {label: "Title", name: "title", widget: "string", tagname: "h2", class: "entry-title"}
- {label: "Body", name: "body", widget: "markdown"}
meta: # Meta data fields. Just like fields, but without any preview element
- {label: "Publish Date", name: "date", widget: "datetime"}
- {label: "Category", name: "category", widget: "string", default: "News"}
if needed, the website’s url is https://distracted-engelbart-20e42f.netlify.com
Any ideas on what I’m doing wrong here?
This post is a few months old so I guess you got this working?
I had to add the admin files to the STATIC_PATHS variable in pelicanconf.py
STATIC_PATHS = [
'admin/index.html',
'admin/config.yml',
'images',
'extra'
]
Here's my example repo with Netlify CMS integrated https://github.com/marcus-clements/pelican-netlify-cms

Implementing prerender SPA plugin to vue2js application

I'm trying to implement very popular prerender SPA plugin.
Documentation say to add module to webpack.config.js but I don't have such file I have webpack.base.conf.js, webpack.dev.conf.js and webpack.prod.conf.js.
In first there is no plugins array but it is in last two. So I injected in them:
new PrerenderSPAPlugin({
// Required - The path to the webpack-outputted app to prerender.
staticDir: path.join(__dirname, 'dist'),
// Required - Routes to render.
routes: [ '/' ],
})
to plugins array and I required it at the top of file. Then I run in command line
> npm run build
> cd dist
> live-server
npm run build created dist folder in root directory and now after I added plugin it additionaly add dist directory in config directory where the webpack.conf files are located. In this new dist folder inside config directory is index.html file which is basically empty html template:
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Not Found</pre>
</body></html>
What I'm doing wrong?
I found my mistake in root component which is App.vue. I didn't have id="app" to my root div.

TemplateDoesNotExist at / home.html

I am trying to get a template to be rendered under my templates folder. I believe I set my views correct, URL settings, and settings for to render the view. However, I keep getting the same error, where the template cannot be found. I keep thinking its a path issue but cant put my finger on the issue. I added my screens of different views of my code.
# In newword/newword/newword/views.py
from django.http import HttpResponse
from django.shortcuts import render
def home(request):
return render(request, 'home.html', {})
# In newword/newword/newword/settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ 'templates/home.html'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
# In newword/newword/newword/urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),`enter code here`
]
# In newword/newword/newword/templates/home.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Home</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
</head>
<body></body>
</html>
# Error Output
TemplateDoesNotExist at /
home.html
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.1.5
Exception Type: TemplateDoesNotExist
Exception Value:
home.html
Exception Location: /usr/local/lib/python3.7/site-packages/django/template/loader.py in get_template, line 19
Python Executable: /usr/local/opt/python/bin/python3.7
Python Version: 3.7.2
Python Path:
['/Users/robertromulus/pythonProjects/newword/newword',
'/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
'/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
'/Users/robertromulus/Library/Python/3.7/lib/python/site-packages',
'/usr/local/lib/python3.7/site-packages']
Server time: Mon, 7 Jan 2019 03:02:48 +0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /Users/robertromulus/pythonProjects/newword/newword/templates/home.html/home.html (Source does not exist)
django.template.loaders.app_directories.Loader: /usr/local/lib/python3.7/site-packages/django/contrib/admin/templates/home.html (Source does not exist)
django.template.loaders.app_directories.Loader: /usr/local/lib/python3.7/site-packages/django/contrib/auth/templates/home.html (Source does not exist)
Traceback Switch to copy-and-paste view
/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py in inner
response = get_response(request) ...
▶ Local vars
/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py in _get_response
response = self.process_exception_by_middleware(e, request) ...
▶ Local vars
/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/Users/robertromulus/pythonProjects/newword/newword/newword/views.py in home
return render(request, 'home.html', {}) ...
▶ Local vars
/usr/local/lib/python3.7/site-packages/django/shortcuts.py in render
content = loader.render_to_string(template_name, context, request, using=using)
I want the home.html to be rendered when I go to the root path of the site.
Problem solved - I need to add another folder then templates, and under templates each html file. This video helped. https://www.youtube.com/watch?v=xp_N4JnxHIk&t=184s&list=PLhTjy8cBISEpXc-yjjSW90NgNyPYe7c9_&index=6

Fatal error: spawn ENOENT

Gruntfile.js content:
grunt.initConfig({
connect: {
server: {
options: {
port: 5005,
base: '.'
}
}
},
qunit: {
all: ['test/*.html']
}
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.registerTask('test', ['connect', 'qunit']);
Test/index.html file content:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
Sitejson - QUnit Test Runner
</title>
<link rel="stylesheet" href="libs/qunit/qunit.css" type="text/css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="libs/qunit/qunit.js" type="text/javascript"></script>
<script src="testcases/tests.js" type="text/javascript"></script>
</body>
</html>
tests.js content:
QUnit.test("hello test", function(assert) {
assert.ok(1 == "1", "Passed!");
});
I am working on Ubuntu / Linux environment. I have also installed Phantomjs and is working fine. Whenever i try to run grunt test I'm receiving a fatal error: spawn ENOENT error.
whereas i try running it on browser its qunit is working fine...
I am not able to identify what the issues. Am i missing some more configuration over here.
grunt test --debug shows me:
Running "connect:server" (connect) task
[D] Task source: /media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-connect/tasks/connect.js
Started connect web server on http://0.0.0.0:5005
Running "qunit:all" (qunit) task
[D] Task source: /media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/tasks/qunit.js
Testing test/index.html [D] ["/media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/phantomjs/main.js","/tmp/1405775714604.2773","test/index.html","{\"timeout\":5000,\"inject\":\"/media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/phantomjs/bridge.js\",\"urls\":[],\"force\":false,\"console\":true,\"httpBase\":false}"]
Fatal error: spawn EACCES
Use the following process:
set the tmpdir environment variable:
setenv TMPDIR=~/tmp
Rerun the grunt task
If it works, set this permanently by adding the following to your .bashrc or .profile:
export TMPDIR=~/tmp
References
Troubleshooting · npm/npm Wiki
Secure Programs HowTo
Environment Variables
FAQ Troubleshooting