두 경로가 있습니다. app.use는 정적 파일을 제공합니다. 브라우저에서 다른 매개 변수를 사용하는 ExpressJS 라우팅
app.use('/test', earlyAccess(), express.static(path.join(__dirname, staticFolder)))
app.get("/test", callback);
app.get("/test/:id", callback);
// Here is the callback
var fileStream = fs.createReadStream(staticFolder + '/test.html');
fileStream.on('open', function() {
fileStream.pipe(res);
});
, 나는
localhost:80/test/1
를 호출하는 경우 - 잘 작동합니다. 하지만
localhost:80/test
으로 전화하면 기본 페이지로 리디렉션됩니다. 서버 콘솔에서 304 경고가 발생했습니다.
expressjs에서 매개 변수를 기반으로하는 경로를 사용하는 방법은 무엇입니까?) (당신이 미들웨어를 쓸 수있는 의미,
app.use("/test/*", (req, res, next) => {
// your callback(req, res);
next();
});
app.get("/test/:id", callback);
app.use
, 그것은 다음 호출 할 것이다;
304는 수정되지 않은 문서임을 나타냅니다. '/ test'의 콜백은 무엇입니까? –
은 HTML을로드합니다. test/: id 및/test는 동일한 html 페이지를로드합니다. – user2325247
콜백 기능을 제공 할 수 있습니까? –