express 앱을 쓰고 있는데 들어오는 URL을 특정 "예상 된"형식으로 표준화하는 미들웨어를 만들고 싶다면 /Docs/PAGE/
과 같은 경로를 /docs/page
으로 변환해야합니다.특급 요청이 변경됩니다. 경로?
나중에 경로 처리 미들웨어를 작성하기 쉽게하려면이 작업을 수행하고 싶습니다. 여기
은 내가 쓴 것입니다 : 그러나
app.use(function(request, response, next) {
var standardisedPath = request.path.toLowerCase().replace(/\/$/, '');
logger.info('Standardising original path %s to %s', request.path, standardisedPath);
request.path = standardisedPath;
next();
});
app.get(/^\/docs.*/i, function(request, response) {
var docPath = request.path + '.md';
response.send(docPath);
});
, 내가 /docs/page.md
를 기대하고있어 비록 http://localhost/docs/PAGE/
예를 들어, 내 애플, /docs/PAGE/.md
응답 방문 할 때.
'standardisedPath'와'normalisedPath'이 같은 변수가 될 수 있습니다 ... – sova
@sova이 시점까지 전체 파일을 찾거나 바꾸는 것을 잊어 버렸습니다. – theonlygusti
'request.path'는 나를 위해 예외를 던집니다. 그 외에 브라우저에서 URL에 소문자 버전을 표시하려는 경우 리디렉션을 생성하려는 것처럼 보입니다. – robertklep