성준영

quiz_3, node 실습

1 +/node_modules
1 +/**
2 + * Created by junyoung on 2017. 4. 6..
3 + */
4 +
5 +var http = require('http'),
6 + path = require('path'),
7 + url = require('url'),
8 + fs = require('fs');
9 +
10 +var DOCUMENT_ROOT = "../quiz_3/";
11 +var server = http.createServer(function (req, res) {
12 + var reqPath = url.parse(req.url).pathname;
13 + if (reqPath === '/') {
14 + reqPath = "2012104095.html";
15 + }
16 +
17 + var fullPath = path.join(process.cwd(), DOCUMENT_ROOT, reqPath);
18 +
19 + fs.readFile(fullPath, "binary", function (err, file) {
20 + if (err) {
21 + if (err.code == "ENOENT") {
22 + console.log("SEND 404 for " + req.url);
23 + res.writeHeader(404, {"Content-Type" : "text/html"});
24 + res.write("<h1>Not Found</h1>");
25 + res.end();
26 + } else{
27 + console.error("Error", err);
28 + res.writeHeader(500, {"Content-Type": "text/plain"});
29 + res.write(err + '\n');
30 + res.end();
31 + }
32 + }
33 + else {
34 + console.log("SEND 200 for " + req.url);
35 + res.writeHeader(200);
36 + res.write(file, "binary");
37 + res.end();
38 + }
39 + });
40 +});
41 +
42 +server.listen(3000, function () {
43 + console.log("server listening on http://localhost:3000");
44 +});
...\ No newline at end of file ...\ No newline at end of file
1 +# Logs
2 +logs
3 +*.log
4 +
5 +# Runtime data
6 +pids
7 +*.pid
8 +*.seed
9 +
10 +# Directory for instrumented libs generated by jscoverage/JSCover
11 +lib-cov
12 +
13 +# Coverage directory used by tools like istanbul
14 +coverage
15 +
16 +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 +.grunt
18 +
19 +# node-waf configuration
20 +.lock-wscript
21 +
22 +# Compiled binary addons (http://nodejs.org/api/addons.html)
23 +build/Release
24 +
25 +# Dependency directory
26 +# https://docs.npmjs.com/cli/shrinkwrap#caveats
27 +node_modules
28 +
29 +# Debug log from npm
30 +npm-debug.log
1 +var express = require('express');
2 +var path = require('path');
3 +var favicon = require('serve-favicon');
4 +var logger = require('morgan');
5 +var cookieParser = require('cookie-parser');
6 +var bodyParser = require('body-parser');
7 +
8 +var index = require('./routes/index');
9 +var users = require('./routes/users');
10 +
11 +var app = express();
12 +
13 +// view engine setup
14 +app.set('views', path.join(__dirname, 'views'));
15 +app.set('view engine', 'ejs');
16 +
17 +// uncomment after placing your favicon in /public
18 +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
19 +app.use(logger('dev'));
20 +app.use(bodyParser.json());
21 +app.use(bodyParser.urlencoded({ extended: false }));
22 +app.use(cookieParser());
23 +app.use(require('node-sass-middleware')({
24 + src: path.join(__dirname, 'public'),
25 + dest: path.join(__dirname, 'public'),
26 + indentedSyntax: true,
27 + sourceMap: true
28 +}));
29 +app.use(express.static(path.join(__dirname, 'public')));
30 +
31 +app.use('/', index);
32 +app.use('/users', users);
33 +
34 +// catch 404 and forward to error handler
35 +app.use(function(req, res, next) {
36 + var err = new Error('Not Found');
37 + err.status = 404;
38 + next(err);
39 +});
40 +
41 +// error handler
42 +app.use(function(err, req, res, next) {
43 + // set locals, only providing error in development
44 + res.locals.message = err.message;
45 + res.locals.error = req.app.get('env') === 'development' ? err : {};
46 +
47 + // render the error page
48 + res.status(err.status || 500);
49 + res.render('error');
50 +});
51 +
52 +module.exports = app;
1 +#!/usr/bin/env node
2 +
3 +/**
4 + * Module dependencies.
5 + */
6 +
7 +var app = require('../app');
8 +var debug = require('debug')('app03:server');
9 +var http = require('http');
10 +
11 +/**
12 + * Get port from environment and store in Express.
13 + */
14 +
15 +var port = normalizePort(process.env.PORT || '3000');
16 +app.set('port', port);
17 +
18 +/**
19 + * Create HTTP server.
20 + */
21 +
22 +var server = http.createServer(app);
23 +
24 +/**
25 + * Listen on provided port, on all network interfaces.
26 + */
27 +
28 +server.listen(port);
29 +server.on('error', onError);
30 +server.on('listening', onListening);
31 +
32 +/**
33 + * Normalize a port into a number, string, or false.
34 + */
35 +
36 +function normalizePort(val) {
37 + var port = parseInt(val, 10);
38 +
39 + if (isNaN(port)) {
40 + // named pipe
41 + return val;
42 + }
43 +
44 + if (port >= 0) {
45 + // port number
46 + return port;
47 + }
48 +
49 + return false;
50 +}
51 +
52 +/**
53 + * Event listener for HTTP server "error" event.
54 + */
55 +
56 +function onError(error) {
57 + if (error.syscall !== 'listen') {
58 + throw error;
59 + }
60 +
61 + var bind = typeof port === 'string'
62 + ? 'Pipe ' + port
63 + : 'Port ' + port;
64 +
65 + // handle specific listen errors with friendly messages
66 + switch (error.code) {
67 + case 'EACCES':
68 + console.error(bind + ' requires elevated privileges');
69 + process.exit(1);
70 + break;
71 + case 'EADDRINUSE':
72 + console.error(bind + ' is already in use');
73 + process.exit(1);
74 + break;
75 + default:
76 + throw error;
77 + }
78 +}
79 +
80 +/**
81 + * Event listener for HTTP server "listening" event.
82 + */
83 +
84 +function onListening() {
85 + var addr = server.address();
86 + var bind = typeof addr === 'string'
87 + ? 'pipe ' + addr
88 + : 'port ' + addr.port;
89 + debug('Listening on ' + bind);
90 +}
1 +{
2 + "name": "app03",
3 + "version": "0.0.0",
4 + "private": true,
5 + "scripts": {
6 + "start": "node ./bin/www"
7 + },
8 + "dependencies": {
9 + "body-parser": "~1.16.0",
10 + "cookie-parser": "~1.4.3",
11 + "debug": "~2.6.0",
12 + "ejs": "~2.5.5",
13 + "express": "~4.14.1",
14 + "morgan": "~1.7.0",
15 + "node-sass-middleware": "0.9.8",
16 + "serve-favicon": "~2.3.2"
17 + }
18 +}
1 +body {
2 + padding: 50px;
3 + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; }
4 +
5 +a {
6 + color: #00B7FF; }
7 +
8 +/*# sourceMappingURL=style.css.map */
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "version": 3,
3 + "file": "style.css",
4 + "sources": [
5 + "style.sass"
6 + ],
7 + "mappings": "AAAA,AAAA,IAAI,CAAC;EACH,OAAO,EAAE,IAAK;EACd,IAAI,EAAE,kDAAmD,GAAG;;AAE9D,AAAA,CAAC,CAAC;EACA,KAAK,EAAE,OAAQ,GAAG",
8 + "names": []
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +body
2 + padding: 50px
3 + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif
4 +
5 +a
6 + color: #00B7FF
1 +var express = require('express');
2 +var router = express.Router();
3 +
4 +/* GET home page. */
5 +router.get('/', function(req, res, next) {
6 + res.render('index', { title: 'Express' });
7 +});
8 +
9 +module.exports = router;
1 +var express = require('express');
2 +var router = express.Router();
3 +
4 +/* GET users listing. */
5 +router.get('/', function(req, res, next) {
6 + res.send('respond with a resource');
7 +});
8 +
9 +module.exports = router;
1 +<h1><%= message %></h1>
2 +<h2><%= error.status %></h2>
3 +<pre><%= error.stack %></pre>
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <title><%= title %></title>
5 + <link rel='stylesheet' href='/stylesheets/style.css' />
6 + </head>
7 + <body>
8 + <h1><%= title %></h1>
9 + <p>Welcome to <%= title %></p>
10 + </body>
11 +</html>
...@@ -49,7 +49,7 @@ th { ...@@ -49,7 +49,7 @@ th {
49 padding: 10px 5px 10px 5px; 49 padding: 10px 5px 10px 5px;
50 border-left: 0; 50 border-left: 0;
51 border-right: 0; 51 border-right: 0;
52 - background-color: gainsboro; 52 + background-color: indianred;
53 } 53 }
54 54
55 .maintitle { 55 .maintitle {
...@@ -88,6 +88,11 @@ div { ...@@ -88,6 +88,11 @@ div {
88 /*모바일*/ 88 /*모바일*/
89 @media screen and (max-width: 768px) { 89 @media screen and (max-width: 768px) {
90 90
91 + .introduce-description {
92 + font-size : 14px;
93 + font-weight: bold;
94 + }
95 +
91 #introduce-image { 96 #introduce-image {
92 width: 40%; 97 width: 40%;
93 height: 40%; 98 height: 40%;
...@@ -113,7 +118,8 @@ div { ...@@ -113,7 +118,8 @@ div {
113 padding: 5px 2px 5px 2px; 118 padding: 5px 2px 5px 2px;
114 border-left: 0; 119 border-left: 0;
115 border-right: 0; 120 border-right: 0;
116 - background-color: gainsboro; 121 + background-color: dodgerblue;
122 +
117 } 123 }
118 124
119 td { 125 td {
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
4 <meta charset="UTF-8"> 4 <meta charset="UTF-8">
5 <title>성준영 소개페이지</title> 5 <title>성준영 소개페이지</title>
6 <link rel="stylesheet" type="text/css" href="./2012104095.css"> 6 <link rel="stylesheet" type="text/css" href="./2012104095.css">
7 + <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
8 +
7 </head> 9 </head>
8 <body> 10 <body>
9 11
......