restify / restify/node-restify

Restify.plugins.serverStatic option "appendRequestPath" is bugged

Open
#1,604 16 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Good First Issue Serve
Dominant language
JavaScript
Stars
10.7k
Forks
975
Avg merge
1d 6h
Merged PRs (30d)
5

Description

  • [ X ] Used appropriate template for the issue type
  • [ X ] Searched both open and closed issues for duplicates of this issue
  • [ X ] Title adequately and concisely reflects the feature or the bug

Bug Report

Restify.plugins.serverStatic option "appendRequestPath" is not working properly.

Restify Version

v6.3.4

Node.js Version

v8.91

Expected behaviour

I expected appendRequestPath = false; to make it so that the request path is not appended to the file path. (As stated in the documentation at http://restify.com/docs/plugins-api/#servestatic)

Actual behaviour

The request path was appended to the file path, despite the fact that appendRequestPath was set to false.

Repro case

index.js

var restify = require('restify');

const server = restify.createServer({
    name: 'myapp',
    version: '1.0.0'
  });

server.get('/endpoint', restify.plugins.serveStatic({
    directory: __dirname, // dirname is /Users/keithlee96/testFolder/test-api
    default: 'index.html',
    appendRequestPath: false
}));

server.listen(9090, function(){
    console.log('%s listening at %s', server.name, server.url);
});

index.html was in the same folder.

I ran the file with node index.js
When I made a get request to localhost:9090/endpoint in postman, I got the error:

{
    "code": "ResourceNotFound",
    "message": "/endpoint; caused by Error: ENOENT: no such file or directory, stat '/Users/keithlee96/testFolder/test-api/endpoint'"
}

Expected the targeted file path to be: '/Users/keithlee96/testFolder/test-api/index.html'

Are you willing and able to fix this?

No, I'm no familiar with typescript, so I don't know how to fix the error myself. I just want it to behave as the documentation http://restify.com/docs/plugins-api/#servestatic says it should. Any help on this would be greatly appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The reproduction is in index.js and uses restify.plugins.serveStatic with appendRequestPath set to false; start by locating the serveStatic implementation and reproducing the request to /endpoint. Done means the option prevents /endpoint from being appended and resolves index.html as described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.