투케이2K

83. (NodeJs) [Mac Os] [nocache] : no cache 캐시 모듈 사용해 Response 응답 반환 시 Cache Control no cache 설정 본문

NodeJs

83. (NodeJs) [Mac Os] [nocache] : no cache 캐시 모듈 사용해 Response 응답 반환 시 Cache Control no cache 설정

투케이2K 2024. 1. 19. 13:59

[개발 환경 설정]

개발 툴 : VS CODE

개발 언어 :NodeJs

 


[app.js : 소스 코드]

// ----------------------------------------------------------------------------------------------

// ---------------------------------------
// [모듈 추가]
// ---------------------------------------
const express = require('express')
const app = express()



// ---------------------------------------
// [모듈 추가]
// ---------------------------------------
app.set('view engine', 'ejs') // [Page] : [Render]
app.set('views', './views') // [Page] : [Render]



// ---------------------------------------
// [모듈 추가]
// ---------------------------------------
var bodyParser = require('body-parser'); // [body-parser 사용]

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());



// ---------------------------------------
// [모듈 추가]
// ---------------------------------------
var nocache = require('nocache'); // [nocache 사용]
app.use(nocache());



// ---------------------------------------
// [전역 변수 선언]
// ---------------------------------------

// ----------------------------------------------------------------------------------------------

// [Get] : Path = [/login] : http://localhost:3000/login
app.get('/login', function (req, res) {
    console.log("")
    console.log("==============================================================================")
    console.log("[Server] :: [App] :: [Path = /login] :: [Start]")
    console.log("--------------------------------------------------------------------------")
    console.log("[INPUT] :: [Headers] :: " + JSON.stringify(req.headers))
    console.log("--------------------------------------------------------------------------")
    console.log("[INPUT] :: [Cookies] :: " + JSON.stringify(req.cookies))
    console.log("--------------------------------------------------------------------------")
    console.log("[INPUT] :: [Query] :: " + JSON.stringify(req.query))
    console.log("--------------------------------------------------------------------------")
    console.log("[INPUT] :: [Body] :: " + JSON.stringify(req.body))
    console.log("==============================================================================")
    console.log("")


    try {

        // [response 헤더 no cache 반환]
        res.status(200).send(JSON.stringify({"result" : "success"})); // [http 반환]

    }
    catch (err) {
        res.status(500).send(JSON.stringify({"result" : err})); // [http 반환]
    }
    
})

// ----------------------------------------------------------------------------------------------

// [Server] : [Start]
//*
app.listen(3000, function () {
    console.log("")
    console.log("==============================================================================")
    console.log("[Server] :: [Port = 3000] :: [Start]")
    console.log("==============================================================================")
    console.log("")
})
// */

// ----------------------------------------------------------------------------------------------
 

[결과 출력]


반응형
Comments