WEB3 - Express

보안

수업소개

Express 애플리케이션을 구현할 때 주의해야 할 보안적인 이슈를 살펴봅시다. 

 

 

 

강의

 

 

 

소스코드

변경사항

main.js

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

{
  "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",
    "url": "git+https://github.com/web-n/Nodejs.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/web-n/Nodejs/issues"
  },
  "homepage": "https://github.com/web-n/Nodejs#readme",
  "dependencies": {
    "body-parser": "^1.18.3",
    "compression": "^1.7.2",
    "express": "^4.16.3",
    "helmet": "^3.12.1",
    "sanitize-html": "^1.18.2"
  }
}

 

댓글

댓글 본문
작성자
비밀번호
graphittie 자세히 보기