expressjs에서 리디렉션 기능이있는 웹 페이지를 제공하려고했습니다. 그러나 어떻게 든 작동하지 않을 수 있습니다. 나는 여기 무언가에 바보가되어야한다.nodejs/expressjs 리디렉션이 작동하지 않습니다.
index.html을 :
<html>
<body>
<div id="clicked"> not clicked </div>
</body>
</html>
server.js :
var express = require("express");
var app = express();
app.get('/', function(req, res) {
console.log("reached root!");
res.redirect("index.html");
});
app.listen(9876);
두 파일은 같은 디렉토리에 있습니다. 브라우저 콘솔에서 로그 "도달 로그"를 볼 수 있지만 404 오류가 발생했습니다 : "찾을 수 없습니다 /index.html". 그러나 외부 웹 페이지로 리디렉션하면 작동 할 수 있습니다. 내가 "res.redirect ("index.html ");" ~ "res.redirect ("http://google.com ");", 완벽하게 작동 할 수 있습니다.
정적 파일을 제공하는 곳을 명시해야합니다. https://expressjs.com/en/starter/static-files.html –