Skip to content

Commit

Permalink
* 302 on top level
Browse files Browse the repository at this point in the history
  • Loading branch information
mabels committed Jan 30, 2018
1 parent 70fafc6 commit d74ea79
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "s3-autoindex",
"version": "1.0.4",
"version": "1.0.5",
"description": "Serve the contents of a S3 bucket (private or public) over HTTP",
"keywords": [
"aws",
Expand Down
8 changes: 8 additions & 0 deletions src/directory-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ export default function directoryMatcher(rq: simqle.Queue, rapp: rxme.Subject,
// not a directory
return;
}
if (!req.url.endsWith('/')) {
const url = `${req.url}/`;
res.statusCode = 302;
res.setHeader('Location', url);
res.write(`<a href="${url}">${url}</a>`);
res.end();
return;
}
// const renderList = renderDirectoryList(mypath, res, rq, rapp, s3, config);
res.statusCode = 200;
res.setHeader('X-s3-autoindex', config.version);
Expand Down
10 changes: 4 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ export function myPath(config: Config, url: string): MyPath {
mypath = `/${mypath}`;
}
}
// console.log(`directoryMatcher:${mypath}:${url}`);
// rapp.next(rxme.LogInfo(`[${req.path}] [${mypath}]`));
if (!mypath.endsWith('/')) {
// not a directory
return new MyPath(mypath, FileType.FILE);
let fileType = FileType.FILE;
if (mypath.endsWith('/')) {
fileType = FileType.DIRECTORY;
}
if (mypath.startsWith('/')) {
mypath = mypath.substr(1);
}
return new MyPath(mypath, FileType.DIRECTORY);
return new MyPath(mypath, fileType);
}

export function RxHttpMatcher(cb:
Expand Down

0 comments on commit d74ea79

Please sign in to comment.