Showing
5 changed files
with
109 additions
and
0 deletions
app/app.js
0 → 100644
1 | +var express = require('express') | ||
2 | + , http = require('http') | ||
3 | + , path = require('path'); | ||
4 | + | ||
5 | +var bodyParser = require('body-parser') | ||
6 | + , static = require('serve-static'); | ||
7 | + | ||
8 | +var expressErrorHandler = require('express-error-handler'); | ||
9 | + | ||
10 | +var app = express(); | ||
11 | +//라우터 객체 참조 | ||
12 | +var router = express.Router(); | ||
13 | + | ||
14 | +//라우팅 함수 등록 | ||
15 | +router.route('/process/login/:name').post(function (req, res) { | ||
16 | + console.log('/process/login/:name 처리함'); | ||
17 | + | ||
18 | + var paramName = req.params.name; | ||
19 | + | ||
20 | + var paramId = req.body.id || req.query.id; | ||
21 | + var paramPassword = req.body.password || req.query.password; | ||
22 | + //GET, POST 모두 고려해서 둘 다 검사 | ||
23 | + | ||
24 | + res.writeHead('200', { 'Content-Type': 'text/html;charset=utf8' }); | ||
25 | + res.write('<h1>Result form Express Server</h1>'); | ||
26 | + res.write('<div><p>Param name : ' + paramName + '</p></div>'); | ||
27 | + res.write('<div><p>Param id : ' + paramId + '</p></div>'); | ||
28 | + res.write('<div><p>Param password : ' + paramPassword + '</p></div>'); | ||
29 | + res.write("<br><br><a href ='/login3.html'>로그인 페이지로 돌아가기</a>"); | ||
30 | + res.end(); | ||
31 | + | ||
32 | +}); | ||
33 | + | ||
34 | +app.set('port', process.env.PORT || 3000); | ||
35 | + | ||
36 | +app.use(bodyParser.urlencoded({ extended: false })); | ||
37 | + | ||
38 | +app.use(static(path.join(__dirname, 'public'))); | ||
39 | + | ||
40 | +app.use('/', router); | ||
41 | + | ||
42 | +//모든 router 처리가 끝난 후 404 오류 페이지 처리 | ||
43 | +var errorHandler = expressErrorHandler({ | ||
44 | + static: { | ||
45 | + '404': 'C:/Users/mingyu/Desktop/git/rest_stop_list/app/public/404.html' | ||
46 | + } | ||
47 | +}); | ||
48 | + | ||
49 | +app.use(expressErrorHandler.httpError(404)); | ||
50 | +app.use(errorHandler); | ||
51 | + | ||
52 | +http.createServer(app).listen(app.get('port'), function () { | ||
53 | + console.log('익스프레스 서버를 시작했습니다.'); | ||
54 | +}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
app/public/404.html
0 → 100644
app/public/login.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | + <head> | ||
4 | + <meta charset="UTF-8"> | ||
5 | + <tilte>로그인 테스트</tilte> | ||
6 | + </head> | ||
7 | + <body> | ||
8 | + <h1>로그인</h1> | ||
9 | + <br> | ||
10 | + <form method="post" action="/process/login/rest_list"> | ||
11 | + <table> | ||
12 | + <tr> | ||
13 | + <td><label>아이디</label></td> | ||
14 | + <td><input type="text" name="id"></td> | ||
15 | + </tr> | ||
16 | + <tr> | ||
17 | + <td><label>비밀번호</label></td> | ||
18 | + <td><input type="text" name="password"></td> | ||
19 | + </tr> | ||
20 | + </table> | ||
21 | + <input type="submit" value="전송" name=""> | ||
22 | + </form> | ||
23 | + </body> | ||
24 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
package-lock.json
0 → 100644
This diff is collapsed. Click to expand it.
package.json
0 → 100644
1 | +{ | ||
2 | + "name": "node", | ||
3 | + "version": "1.0.0", | ||
4 | + "description": "", | ||
5 | + "main": "index.js", | ||
6 | + "scripts": { | ||
7 | + "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | + }, | ||
9 | + "author": "", | ||
10 | + "license": "ISC", | ||
11 | + "dependencies": { | ||
12 | + "body-parser": "^1.20.0", | ||
13 | + "express": "^4.18.1", | ||
14 | + "express-error-handler": "^1.1.0", | ||
15 | + "http": "^0.0.1-security", | ||
16 | + "path": "^0.12.7", | ||
17 | + "serve-static": "^1.15.0" | ||
18 | + } | ||
19 | +} |
-
Please register or login to post a comment