Restlet: use "index.html" as default for serving static content using CLAP protocol - restlet

I want to put static content in my restlet based web service. The static part must reside into the jar of the service. The code I'm using is:
Directory directory = new Directory(getContext(), "clap://class/pageData");
router.attach("/page", directory);
If I access the service with .../page/index.html the page is displayed in the browser. But the call of .../page or .../page/ results in a "Not found" error page.
How can I make index.html the default file?

You should try to specify implicitely the indexName property on your directory:
Directory directory = new Directory(
getContext(), "clap://class/pageData");
directory.setIndexName("index.html");
router.attach("/page", directory);
It seems that the default value is index and not index.html...
Hope it helps you,
Thierry

Related

Nuxt JS - reading conf/env file in static site generation

My project with Nuxt JS is set with target:static and ssr: false.
This app need to connect to a local endpoint to retrieve some informations.
I have multiple endpoints and I need multiple instances of the app, every app must read only his endpoint.
The question is: how change the endpoint address for every app without rebuild everyone?
I tried with env file or a json file in the static folder (in order to have access to this file in the dist folder after the build process).
But if I modify the content of the env/json file in the dist folder and then reload the webpage (or also restart the web server that serve the dist folder), the app continue to use the original endpoint provided at the build time.
There is a way or I have to switch to server side rendering mode (which I would rather not use)?
Thank you!
When you use SSG, it will bundle your app at build time. Last time I checked, there was no hack regarding that. (I don't have the Github issue under my hand but it's a popular one)
And at the same time, I don't really see how it would be done since you want to mix something static and dynamic at the same time.
SSR is the only way here.
Otherwise, you may have some other logic to generate dynamic markup when updating your endpoints (not related to Nuxt) by fetching a remote endpoint I guess.
With the module nuxt content it's possible to create a folder "/content" in project directory and read json files from that directory.
After, when creating the dist with nuxt generate command, the "content" folder it's included in "_nuxt" folder of the dist and if you modify the content of the json file and refresh the webpage that read it, will take the new values.

NextJS doesn't create index.html for subfolders in static export

I made a fully static website using NextJS, exported it and I'm hosting it on S3 using static website hosting. I can click around and successfully view all the pages, including example.com/blog. However if in the browser I click refresh, or enter example.com/blog directly, I get a 404 Not Found error.
When viewing the exported files, I see that /blog/ has no index.html file, even though there should be (in my opinion) since in the original source files I have a /blog/index.ts file, and when in dev mode I can refresh localhost/blog or enter it directly and it works as expected.
In summary, I believe NextJS should create a /blog/index.html file but it doesn't. Is there any way to force this? Am I doing something wrong? Thank you!
To generate an index.html file when exporting to static HTML, enable the trailingSlash setting in your next.config.js:
module.exports = {
trailingSlash: true,
}
./out/blog.html should now become ./out/blog/index.html after the export.

Securing GitLab Pages with Let's Encrypt gets 404

I am following this tutorial https://about.gitlab.com/2016/04/11/tutorial-securing-your-gitlab-pages-with-tls-and-letsencrypt/
Next step instructions are:
Make sure your web server displays the following content at
http://YOURDOMAIN.org/.well-known/acme-challenge/5TBu788fW0tQ5EOwZMdu1Gv3e9C33gxjV58hVtWTbDM
before continuing:
5TBu788fW0tQ5EOwZMdu1Gv3e9C33gxjV58hVtWTbDM.ewlbSYgvIxVOqiP1lD2zeDKWBGEZMRfO_4kJyLRP_4U
#
# output omitted
#
Press ENTER to continue
According to the tutorial, it's using Jekyll, but I don't use a static html generator like jekyll. The files are all static html. I created the exact path under root folder: /.well-known/acme-challenge/PukY0bbiH3nRfciQ4IzwTDIXFn4G5sZ5I-LkMz3-KHE.html
But after the piplines jobs are done, I am still getting 404. What's the problem here?
I had problem same yesterday and I found the solution, I hope it is not too late to share with you. According to this tutorial here, the "well-known" folder should be under the "public" folder.
And the letsencrypt need to access a .html file in the following path using the browser.
http://YOURDOMAIN.org/.well-known/acme-challenge/5TBu788fW0tQ5EOwZMdu1Gv3e9C33gxjV58hVtWTbDM
To do this, you must create the "index.html" file in the path below inside your gitlab repository.
public/.well-known/acme-challenge/5TBu788fW0tQ5EOwZMdu1Gv3e9C33gxjV58hVtWTbDM/index.html
In the "index.html" file you should put only the following sentence:
5TBu788fW0tQ5EOwZMdu1Gv3e9C33gxjV58hVtWTbDM.ewlbSYgvIxVOqiP1lD2zeDKWBGEZMRfO_4kJyLRP_4U
important: do not put any html tag, just the plain text above.
Then just continue following the tutorial. Good luck.

Web2py & nginx - do I have to set up static folder

I'm running nginx/uWSGI and trying to lock down a web2py site using 'auth.requires_login()' (https://groups.google.com/forum/#!topic/web2py/0j92-sPp4bc) so that only logged in users can get to it, even the content under /static/. If I set up nginx config file with
location ~* /(\w+)/static/ {
root /home/www-data/web2py/applications/;
}
as recommended in the docs, won't that bypass the access control, and allow anyone to see the static content? If I leave this line out of the config file, will web2py still share the static content to logged-in users (although presumably a little slower)?
Yes, using that nginx rule will bypass web2py. Removing it and letting web2py handle /static/ won't change much either, as this is directly from the web2py manual:
http://127.0.0.1:8000/a/static/filename
There is no controller called "static". web2py interprets this as a request for the file called "filename" in the subfolder "static" of the application "a".
When static files are downloaded, web2py does not create a session, nor does it issue a cookie or execute the models.
So because there is no controller, you cannot directly use auth.requires_login() for static content. This is because files in /static/ are generally not meant to be access-controlled, or else browsers will not be able to get the css, js, etc. needed to even render the welcome or login page.
However, if you still want site-wide access control to static files (i.e. private pdf files) you can do it like so:
in your application directory, create a folder called private_static
then in your controller add the following:
#default.py
import os
auth.requires_login()
def private_static():
filename = os.path.join(*request.args)
allowed = ['private1.pdf', 'private2.pdf'] # have some kind of validation for security!
if not filename in allowed:
raise HTTP(404)
return response.stream(open(os.path.join(request.folder, 'private_static', filename)))
and in your view something like the following:
Private Document
Now accessing http://.../private_static/private1.pdf will force the user to login before getting the static file.

Link to file outside context root of weblogic

If I want to display an image in my webpage and its src is a file outside context root.
At the IDE, the image is shown to be loaded.
But when I test the web page, nothing displayed.
How can I config weblogic server to allow the image to be displayed. If not is there anyway to run around this problem.
Thanks a lot.
You can use the Virtual Directory Mapping feature (that you declare in the weblogic.xml):
Using the virtual directory mapping
feature, you can create one directory
to serve static files such as images
for multiple Web Applications. For
example, you would create a mapping
similar to the folowing:
<virtual-directory-mapping>
<local-path>c:/usr/gifs</local-path>
<url-pattern>/images/*</url-pattern>
</virtual-directory-mapping>
A request to
http://localhost:7001/mywebapp/images/test.gif
will cause your WebLogic Server
implementation to look for the
requested image at:
c:/usr/gifs/images/*.
This directory must be located in the
relative uri, such as
"/images/test.gif".