Raspberry Pi에서 NodeJS 서버가 함수를 호출하지 않음


1

나는 현재 Raspian OS를 실행중인 노드 JS 서버가 포트 8080에서 실행되고있다. 그런 다음 NGINX를 역 프록시로 사용하여 들어오는 포트 80 트래픽을 내 서버로 8080으로 라우팅하도록 설정했다.

사용자가 HTML 버튼을 클릭하여 NodeJS 함수를 호출하여 Google로 리디렉션하도록하려고합니다. 이제 문제가 코드에 있다고 생각하지 않습니다. 로컬 컴퓨터 (nginx 필요 없음)에서 서버를 실행하면 모든 것이 제대로 작동하기 때문입니다. 그러나 내 로컬 컴퓨터에서 Raspberry Pi를 실행하는 서버에 액세스하려고 할 때 : http://192.168.0.103/Authenticate.html 버튼을 사용하여 HTML 페이지를 처리하지만 함수 호출 http://192.168.0.103/Authenticate.js 나에게 404 오류를 준다.

나는이 역방향 프록시에서 뭔가 잘못된 설정이 있다고 생각하지만, 나는 이것에 아주 새로운 것이므로 전혀 모른다. 어떤 도움을 주셔서 감사합니다.

NGINX 기본 파일

    {
    listen 80;
    listen [::]:80;
    root /home/pi/Cortana;
    server_name _;
    location / {
        proxy_pass http://127.0.0.1:8080;
        try_files $uri 4uri/ =404;
    }
}

OAuthTest.html

<form method="post" action="/Authenticate.js">
    <input type="submit" value="Login with Reddit" >
</form>

OAuthTest.js

const http = require('http');
const request = require('request');
const fs = require('fs');
const express = require('express');

const app = express();
const server = http.createServer(app);

app.get('/', serveDefaultHTML);
app.get('/OAuthTest.html', serveAuthHTML);
app.post("/Authenticate.js", function(req, res){
    console.log("Here");
    redirecting(req, res);
    });


server.listen(8080, function(){
    console.log("Listening on http://localhost:8080");
});

function serveAuthHTML(req, res){
    fs.readFile("OAuthTest.html", function(err, data){
        if (err){
            res.writeHead(404, {'Content-Type': 'text/html'});
            res.end(err);
            return;
        }
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.end(data);
    });
}

function serveDefaultHTML(req, res){
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write("Welcome to my server!")
    res.end("Request url: " + req.url);
}

function redirecting(req, res){
    console.log("Redirecting");
    res.writeHead(301,
        {Location: 'http://www.google.com'}
    );
    res.end();
}
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.