수업소개
Express 애플리케이션을 구현할 때 주의해야 할 보안적인 이슈를 살펴봅시다.
강의
소스코드
main.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | var express = require( 'express' ); var app = express(); var fs = require( 'fs' ); var bodyParser = require( 'body-parser' ); var compression = require( 'compression' ); var helmet = require( 'helmet' ) app.use(helmet()); var indexRouter = require( './routes/index' ); var topicRouter = require( './routes/topic' ); app.use(express.static( 'public' )); app.use(bodyParser.urlencoded({ extended: false })); app.use(compression()); app.get( '*' , function (request, response, next){ fs.readdir( './data' , function (error, filelist){ request.list = filelist; next(); }); }); app.use( '/' , indexRouter); app.use( '/topic' , topicRouter); app.use( function (req, res, next) { res.status(404).send( 'Sorry cant find that!' ); }); app.use( function (err, req, res, next) { console.error(err.stack) res.status(500).send( 'Something broke!' ) }); app.listen(3000, function () { console.log( 'Example app listening on port 3000!' ) }); |
package.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | { "name" : "web2-nodejs" , "version" : "1.0.0" , "description" : "" , "main" : "main.js" , "directories" : { "lib" : "lib" }, "scripts" : { "test" : "echo \"Error: no test specified\" && exit 1" }, "repository" : { "type" : "git" , }, "author" : "" , "license" : "ISC" , "bugs" : { }, "dependencies" : { "body-parser" : "^1.18.3" , "compression" : "^1.7.2" , "express" : "^4.16.3" , "helmet" : "^3.12.1" , "sanitize-html" : "^1.18.2" } } |