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

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.

Related

static site hosting on S3 - 404 errors on files that show in S3 management console

I'm hosting a site using S3. Until recently, no problems. Last week, I uploaded some new .html files, and all of these new files result in a 404 error, while older .html files load with no problems.
I can see the new files in the S3 bucket using the web interface. When I compare permissions and any other settings for the new vs. old files, I'm not able to see any difference. When I view the properties of a new file, the provided link works (none of my images or CSS loads, however). Also, I can get the file to load using the bucket's endpoint. But, when using our custom domain name, all new files fail to load, with the following error:
404 Not Found
Code: NoSuchKey
Message: The specified key does not exist.
Key: test1/s3a-debug.html
RequestId: 2573FF0356xxxxxxxxxx
HostId: qYnv8alWnV/xxxxxxxxx/xxxxxxxxxxxx+NPkHLO8arfTVizUds=
I'm at a loss to explain why recently uploaded files throw a 404, and yet older files that look identical load just fine. I've seen other people report similar problems, but I've yet to find a thread with a solution.
any help would be greatly appreciated. Thanks!
Go to S3 bucket properties -> Static web hosting and add index.html as Error document.
It considers everything as directory once you append something to host URL. Now after adding index.html as Error document, when it doesn't find the required path as a folder, it will go to index.html and redirect your request.

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.

Website not loading on LAMP but test page displays

I have set up my LAMP server on Ubuntu 14.04. I have created a virtual machine to host a website. The directory structure is:
var/www/DS/public_html
I have set up my configuration files so that the server responds to the url:
http://ds.local
I have created test pages inside public_html called index.html and index.php. I have modified the configurations so that index.php is the default page that gets served. In the test page named index.php, the only line of code is:
<?php phpinfo(); ?>
when I go to http://ds.local frrom my browser, the page gets served up and I can see all my php configurations. So. everything good till now.
I have a website which I had developed on WAMP. Now, when I try transferring the files of this website into public_html and try reloading the browser, nothing happens. I have looked at the developer tools window, and I am certain that no page loads.
I have ensured that I have copied all the files and folders making up the website, including all the folders containing js and css. I have also ensured that there exists a file called index.php
Where am I going wrong?
I have a website which I had developed on WAMP
Are you sure that all files are referenced by correct case?
Windows file systems are by default case-insensitive.
http://localhost/DS and http://localhost/ds
are same on windows but not on linux/unix.

get apache to serve a static file named index.html?parameter=1

I am working on a website on a low memory server. I edit/update the website in a CMS and then do a nighly wget to an other folder/vhost that serves fast static pages to the users.
It works great and fast, but now I found out that I have some pages that don't work.
Wget downloads index.php?id=10 and creates the file index.html?id=10.html
One specific folder of my website has the files index.html, index.html?id=1, index.html?id=2, index.html?id=3 etc
When i open www.mysite.com/myfolder/index.html?id=1.html in my browser i get index.html, even if the file index.html?id=1.html exists.
Does anybody have any solution for how to fix this? maybe an htaccess solution or something else?
I am looking forward to any ideas,

How to use relative URL's in website with two base URL's

I have our basic corporate static html website installed in our web root directory and our billing software installed in /portal. I have integrated the websites to look like a single site by including the /menu.tpl smarty template file in the /portal/header.tpl file. However, if I use relative URL's, the menu sysem doesnt work as the base url for the billing script is /portal. i.e. if I create a link to faq.php in the menu.tpl and I load a page on the portal site, the link in the menu back to the faq page is now /portal/faq.php whereby if I load a page off the root site the link is just /faq.php as it should be.
The obvious answer is to just use absolute URL's, but I need the site to be portable as I have many developers who need to install and test it.
I cant find anyway to resolve this. Any ideas?
I ran into the same problem as you a while ago, and after trying a lot of dead ends, I finally ended up with the following solution:
For any URL you need to be a chamelion, i.e. change its path depending on the environment, insert a PHP function that writes out the correct URL.
If you include the PHP function from a single central file, then you can change all of the URL's in the entire site automatically, based on a setting, or some pre-detected switch such as the current domain name, etc.
Example:
<?php print_base_url_plus("/menu.php"); ?>
... where print_base_url_plus() is a function which appends the base URL onto the output.
You may find that you have to change some of the URL's to be php, so they are preprocessed by the PHP engine, or, you can alter the web settings so that standard .htm files are piped through the PHP engine, just like .php files.