Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http status 412 on simple proxy/web server #1194

Open
wa1gon opened this issue Jul 26, 2017 · 0 comments
Open

http status 412 on simple proxy/web server #1194

wa1gon opened this issue Jul 26, 2017 · 0 comments

Comments

@wa1gon
Copy link

wa1gon commented Jul 26, 2017

I have written this simple proxy/static web server that first checks to see if a local copy exist, if not then it proxy to an application server.

It is a simple GET request with no query strings.

Here is the guts of the code:

server.createServer((req: Request, res: any) => {

  let fileName = isFileLocal(req.url);

  if (fileName) {

    fs.readFile(fileName, "binary", function (err: string, file: any) {
      if (err) {
        res.writeHead(500, { "Content-Type": "text/plain" });
        res.write(err + "\n");
        res.end();
        return;
      } else {

        res.writeHead(200, { "Cache-Control": "no-cache, no-store, must-revalidate" });
        res.write(file, "binary");
        res.end();
      }
    });
  } else {
    console.log("Proxying Request: %s", hostname + req.url);
    console.log(req.headers)
    proxy.web(req, res, { target: hostname + req.url });
    // res.writeHead(200, { 'Content-Type': 'text/plain' });
    // res.write('Request successfully proxies!' + '\n' + JSON.stringify(req.headers));
    // res.end();
  }
}).listen(port);

Suggestions on what I am doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant