Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- cyber.shinhan
- ISO25000
- angular-cli
- Cheerio
- 품질 표준
- pylint
- angular
- 품질
- 네이버 클라우드 플랫폼
- phantomjs
- docker
- 크롤링
- 소프트웨어
- npm repository
- casperJS
- 페이지구분
- angular2
- angular2 google analytics
- RxJS
- 구글 클라우드 플랫폼
- REQUEST
- SW
- Nexus
- 신한대학교
- nodejs
- vscode
- 서버
- 도커
- ISO25010
- ISO9126
Archives
- Today
- Total
나를 위한 기록들
NodeJS https 설정, SSL 본문
// 소스코드
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const http = require('http');
const https = require('https');
const fs = require('fs');
const index = require('./routes/index');
const users = require('./routes/users');
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
app.use('/users', users);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
app.get('*', cors(), function(req, res, next){
res.sendfile(path.join(__dirname, 'public/index.html'));
});
const options = {
key: fs.readFileSync('경로~/key.pem'),
cert: fs.readFileSync('경로~/cert.pem')
};
const port1 = 80; // http 포트
const port2 = 443; // https 포트
http.createServer(app).listen(port1, function(){
console.log("Http server listening on port " + port1);
});
https.createServer(options, app).listen(port2, function(){
console.log("Https server listening on port " + port2);
});
module.exports = app;
Comments