Nodejs

 

 

 

app7.js

var express =require('express');
var http=require('http');
var static=require('serve-static');
var path=require('path')

var bodyParser=require('body-parser');

var app=express();

app.set('port', process.env.PORT  || 3000);
app.use('/public' ,static(path.join(__dirname, 'public')));

//포스트방식으로 넘길때
app.use(bodyParser.urlencoded({extend:false}));
app.use(bodyParser.json());


app.use(function(req, res, next){
    console.log('첫번째 미들웨어 호출됨.') ;
    
    var userAgent =req.header('User-Agent');
    //post 혹은 get 방식
    var paramId=req.body.id || req.query.id;
    
    res.send('<h3>서버에서 응답 : User-Agent -> '+userAgent+'</h3> <h3>Param ID-> '+paramId+'</h3>');         
    
});



var server=http.createServer(app).listen(app.get('port'), function(){
   console.log('익스프레스로 웹 서버를 실행함 : '  + app.get('port')) ;
});


//npm install body-parser --save 모듈 인스톨

 

 

login.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>로그인</title>
    </head>
    <body>
        <h1>로그인</h1>
        <br>
        <form method="post" action="app7.js">
            <table>
                <tr>
                    <td><label>아이디</label></td>
                    <td><input type="text" name="id"></td>
                </tr>
                <tr>
                    <td><label>비밀번호</label></td>
                    <td><input type="password" name="password"></td>
                </tr>
            </table>
            <input type="submit" value="전송" name="">
        </form>
    </body>
</html>




 

 

https://github.com/braverokmc79/nodejs_webproject1

 

 

 

about author

PHRASE

Level 60  라이트

기선을 제압하면 주도권을 잡는다. -손자병법

댓글 ( 0)

댓글 남기기

작성

Nodejs 목록    more