헤더 X-Powered-By : Express를 제거 할 수 없습니다 :
Express로 nodejs에서 서버를 실행 중입니다. 헤더를 제거 할 수없는 것 같습니다.
X-Powered-By:Express
이 헤더를 제거 할 수있는 방법이 있는지 궁금하거나 그와 함께 살아야합니까?
Express> = 3.0.0rc5에서 :
app.disable('x-powered-by');
다음은 이전 버전의 Express에서 헤더를 제거하는 간단한 미들웨어입니다.
app.use(function (req, res, next) {
res.removeHeader("x-powered-by");
next();
});
rjack의 답변을 피기 백하기 위해 X-powered-by 헤더를 다음과 같이 훨씬 더 시원하고 사용자 정의 할 수 있습니다 (선택 사항).
app.use(function (req, res, next) {
res.header("X-powered-by", "Blood, sweat, and tears")
next()
})
Express v3.0.0rc5부터는 X-Powered-By
헤더 비활성화 지원 이 내장되어 있습니다.
var express = require('express');
var app = express();
app.disable('x-powered-by');
소스에서 ( http://expressjs.com/en/api.html#app.set ) Express 4.X에서는 아래 줄을 사용하여 앱을 설정하면됩니다.
app.set('x-powered-by', false) // hide x-powered-by header!
다음은 X-Powered-By를 교체하기 위해 사용할 수있는 편리한 미들웨어입니다.
function customHeaders( req, res, next ){
// Switch off the default 'X-Powered-By: Express' header
app.disable( 'x-powered-by' );
// OR set your own header here
res.setHeader( 'X-Powered-By', 'Awesome App v0.0.1' );
// .. other headers here
next()
}
app.use( customHeaders );
// ... now your code goes here
이 경우 X-Powered by를 설정하면 기본 'Express'가 무시되므로 새 값을 비활성화하거나 설정할 필요가 없습니다.
어쩌면 이것은 더 노련한 Express 사용자에게는 분명 할 수 있지만 이것이 나에게 효과적이었습니다.
app.configure(function() {
app.use(function (req, res, next) {
res.removeHeader("X-Powered-By");
next();
});
});
https://github.com/visionmedia/express/blob/master/lib/http.js#L72 코드를 읽으면 조건부처럼 보이지 않기 때문에 함께 살아야한다고 생각합니다.
nginx / apache 프론트 엔드가 있다면 헤더를 제거 할 수 있습니다 (아파치의 경우 mod_headers, nginx의 경우 헤더-더 있음)
숨기기, X-Powered By의 경우 Node .js 라이브러리 헬멧을 사용할 수 있습니다 .
그 링크는 헬멧입니다
var helmet = require('helmet');
app.use(helmet.hidePoweredBy());
removeHeader는 경로 미들웨어, 커피 스크립트 예제에서만 작동합니다.
fix_headers = (req, res, next) ->
res.removeHeader 'X-Powered-By'
next()
app.get '/posts', fix_headers, (req, res, next) ->
...
참고URL : https://stackoverflow.com/questions/5867199/cant-get-rid-of-header-x-powered-byexpress
'IT' 카테고리의 다른 글
문자열의 마지막 문자는 어떻게 얻습니까? (0) | 2020.05.29 |
---|---|
튜플을 목록으로 변환 (0) | 2020.05.29 |
CFStringRef를 NSString로 변환하는 방법? (0) | 2020.05.29 |
Xcode 5.1-컴파일 할 아키텍처가 없습니다 (ONLY_ACTIVE_ARCH = YES, 활성 아치 = x86_64, VALID_ARCHS = i386) (0) | 2020.05.29 |
React.js : 한 컴포넌트를 다른 컴포넌트로 랩핑 (0) | 2020.05.29 |