Browse Source

FileServer: enhance returned error page for 404 response

Manfred Kröhnert 10 years ago
parent
commit
f71ad614cb
3 changed files with 33 additions and 8 deletions
  1. 13 3
      cli/js/AmberCli.js
  2. 7 2
      cli/st/AmberCli.st
  3. 13 3
      cli/support/amber-cli.js

+ 13 - 3
cli/js/AmberCli.js

@@ -810,12 +810,22 @@ if(! smalltalk.assert($1)){
 $3=self._respondFileNamed_to_(self._fallbackPage(),aResponse);
 return $3;
 };
-_st(aResponse)._writeHead_options_((404),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
-_st(aResponse)._write_("404 Not found");
+_st(aResponse)._writeHead_options_((404),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/html")]));
+_st(aResponse)._write_("<html><body><p>404 Not found</p>");
+$ctx1.sendIdx["write:"]=1;
+_st(aResponse)._write_("<p>Did you forget to put an index.html file into the directory which is served by \x22bin/amber serve\x22? To solve this you can:<ul>");
+$ctx1.sendIdx["write:"]=2;
+_st(aResponse)._write_("<li>create an index.html in the served directory.</li>");
+$ctx1.sendIdx["write:"]=3;
+_st(aResponse)._write_("<li>can also specify the location of index.html with the \x22--fallback-page\x22 option.</li>");
+$ctx1.sendIdx["write:"]=4;
+_st(aResponse)._write_("<li>change the directory to be served with the \x22--base-path\x22 option.</li>");
+$ctx1.sendIdx["write:"]=5;
+_st(aResponse)._write_("</ul></p></body></html>");
 $4=_st(aResponse)._end();
 return self}, function($ctx1) {$ctx1.fill(self,"respondNotFoundTo:",{aResponse:aResponse},smalltalk.FileServer)})},
 args: ["aResponse"],
-source: "respondNotFoundTo: aResponse\x0a\x09self fallbackPage isNil ifFalse: [^self respondFileNamed: self fallbackPage to: aResponse].\x0a\x09aResponse \x0a\x09\x09writeHead: 404 options: #{'Content-Type' -> 'text/plain'};\x0a\x09\x09write: '404 Not found';\x0a\x09\x09end",
+source: "respondNotFoundTo: aResponse\x0a\x09self fallbackPage isNil ifFalse: [^self respondFileNamed: self fallbackPage to: aResponse].\x0a\x09aResponse \x0a\x09\x09writeHead: 404 options: #{'Content-Type' -> 'text/html'};\x0a\x09\x09write: '<html><body><p>404 Not found</p>';\x0a\x09\x09write: '<p>Did you forget to put an index.html file into the directory which is served by \x22bin/amber serve\x22? To solve this you can:<ul>';\x0a\x09\x09write: '<li>create an index.html in the served directory.</li>';\x0a\x09\x09write: '<li>can also specify the location of index.html with the \x22--fallback-page\x22 option.</li>';\x0a\x09\x09write: '<li>change the directory to be served with the \x22--base-path\x22 option.</li>';\x0a\x09\x09write: '</ul></p></body></html>';\x0a\x09\x09end",
 messageSends: ["ifFalse:", "isNil", "fallbackPage", "respondFileNamed:to:", "writeHead:options:", "->", "write:", "end"],
 referencedClasses: []
 }),

+ 7 - 2
cli/st/AmberCli.st

@@ -339,8 +339,13 @@ respondNotCreatedTo: aResponse
 respondNotFoundTo: aResponse
 	self fallbackPage isNil ifFalse: [^self respondFileNamed: self fallbackPage to: aResponse].
 	aResponse 
-		writeHead: 404 options: #{'Content-Type' -> 'text/plain'};
-		write: '404 Not found';
+		writeHead: 404 options: #{'Content-Type' -> 'text/html'};
+		write: '<html><body><p>404 Not found</p>';
+		write: '<p>Did you forget to put an index.html file into the directory which is served by "bin/amber serve"? To solve this you can:<ul>';
+		write: '<li>create an index.html in the served directory.</li>';
+		write: '<li>can also specify the location of index.html with the "--fallback-page" option.</li>';
+		write: '<li>change the directory to be served with the "--base-path" option.</li>';
+		write: '</ul></p></body></html>';
 		end
 !
 

+ 13 - 3
cli/support/amber-cli.js

@@ -38893,12 +38893,22 @@ if(! smalltalk.assert($1)){
 $3=self._respondFileNamed_to_(self._fallbackPage(),aResponse);
 return $3;
 };
-_st(aResponse)._writeHead_options_((404),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
-_st(aResponse)._write_("404 Not found");
+_st(aResponse)._writeHead_options_((404),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/html")]));
+_st(aResponse)._write_("<html><body><p>404 Not found</p>");
+$ctx1.sendIdx["write:"]=1;
+_st(aResponse)._write_("<p>Did you forget to put an index.html file into the directory which is served by \x22bin/amber serve\x22? To solve this you can:<ul>");
+$ctx1.sendIdx["write:"]=2;
+_st(aResponse)._write_("<li>create an index.html in the served directory.</li>");
+$ctx1.sendIdx["write:"]=3;
+_st(aResponse)._write_("<li>can also specify the location of index.html with the \x22--fallback-page\x22 option.</li>");
+$ctx1.sendIdx["write:"]=4;
+_st(aResponse)._write_("<li>change the directory to be served with the \x22--base-path\x22 option.</li>");
+$ctx1.sendIdx["write:"]=5;
+_st(aResponse)._write_("</ul></p></body></html>");
 $4=_st(aResponse)._end();
 return self}, function($ctx1) {$ctx1.fill(self,"respondNotFoundTo:",{aResponse:aResponse},smalltalk.FileServer)})},
 args: ["aResponse"],
-source: "respondNotFoundTo: aResponse\x0a\x09self fallbackPage isNil ifFalse: [^self respondFileNamed: self fallbackPage to: aResponse].\x0a\x09aResponse \x0a\x09\x09writeHead: 404 options: #{'Content-Type' -> 'text/plain'};\x0a\x09\x09write: '404 Not found';\x0a\x09\x09end",
+source: "respondNotFoundTo: aResponse\x0a\x09self fallbackPage isNil ifFalse: [^self respondFileNamed: self fallbackPage to: aResponse].\x0a\x09aResponse \x0a\x09\x09writeHead: 404 options: #{'Content-Type' -> 'text/html'};\x0a\x09\x09write: '<html><body><p>404 Not found</p>';\x0a\x09\x09write: '<p>Did you forget to put an index.html file into the directory which is served by \x22bin/amber serve\x22? To solve this you can:<ul>';\x0a\x09\x09write: '<li>create an index.html in the served directory.</li>';\x0a\x09\x09write: '<li>can also specify the location of index.html with the \x22--fallback-page\x22 option.</li>';\x0a\x09\x09write: '<li>change the directory to be served with the \x22--base-path\x22 option.</li>';\x0a\x09\x09write: '</ul></p></body></html>';\x0a\x09\x09end",
 messageSends: ["ifFalse:", "isNil", "fallbackPage", "respondFileNamed:to:", "writeHead:options:", "->", "write:", "end"],
 referencedClasses: []
 }),