투케이2K

46. (NodeJs) [Mac Os] [Response] : response 응답 시 header 헤더 값 json 형태 다중 값 반환 본문

NodeJs

46. (NodeJs) [Mac Os] [Response] : response 응답 시 header 헤더 값 json 형태 다중 값 반환

투케이2K 2024. 1. 7. 11:23

[개발 환경 설정]

개발 툴 : 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]

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

//app.use(express.urlencoded({ extended: true })) // [Http] : [URL] : [Encode]

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

app.use(express.json()) // [Http] : [Body] : [Json]

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

// [Get] : Path = [/responseReturn] : http://localhost:3000/responseReturn?id=admin&pw=123
app.get('/responseReturn', function (req, res) {
    console.log("")
    console.log("==============================================================================")
    console.log("[Server] :: [Get] :: [Path = /responseReturn] :: [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] :: [Params] :: " + JSON.stringify(req.query))
    console.log("--------------------------------------------------------------------------")
    console.log("[INPUT] :: [Body] :: " + JSON.stringify(req.body))
    console.log("==============================================================================")
    console.log("")


    // [인풋 파라이터 값 체크]
    if (req.query.id != undefined && req.query.id != "" && req.query.pw != undefined && req.query.pw != ""){
        res.status(200).header({
            "Token1": "abcdefg1234567890",
            "Token2": "1234567890abcdefg"
        }).send(JSON.stringify({"result" : "success"}));
    }
    else {
        res.status(403).send(JSON.stringify({"result" : "error"}));
    }

})

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

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

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

[결과 출력]

 

 
반응형
Comments