Last active
September 2, 2017 15:53
-
-
Save kkeeth/341ff8fd28ed8ecd99fb8ce69ba34be4 to your computer and use it in GitHub Desktop.
nodejs勉強会用ファイルリスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="ja"> | |
<head> | |
<title>BBS</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"> | |
<link rel="stylesheet" media="all" href="/css/style.css"> | |
</head> | |
<body> | |
<h2>Chat App by Node.js!</h2> | |
<ul id="posts"> | |
<% for (var i = 0; i < posts.length; i++) { %> | |
<li><%= posts[i] %></li> | |
<% } %> | |
</ul> | |
<form method="POST"> | |
<input type="text" name="txt"> | |
<button>Post!!</button> | |
</form> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="ja"> | |
<head> | |
<title>BBS</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"> | |
<link rel="stylesheet" media="all" href="/css/style.css"> | |
</head> | |
<body> | |
<h2>Chat App by Node.js!</h2> | |
<form method="POST"> | |
<input type="text" name="txt"> | |
<button>Post!!</button> | |
</form> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'), | |
fs = require('fs'), | |
qs = require('querystring') | |
const settings = require('./settings') | |
const server = http.createServer() | |
const template = fs.readFileSync(`${__dirname}/views/bbs.html`, 'utf-8') | |
let posts = [] | |
server.on('request', (req, res) => { | |
if (req.url === '/favicon.ico') { | |
return | |
} | |
if (req.url === "/css/style.css") { | |
fs.readFile('./css/style.css', 'UTF-8', (err, data) => { | |
res.writeHead(200, {'Content-Type': 'text/css'}) | |
res.write(data) | |
res.end() | |
}) | |
return | |
} | |
res.writeHead(200, {'Content-Type': 'text/html'}) | |
res.write(template) | |
res.end() | |
}) | |
server.listen(settings.port, settings.host) | |
console.log('server listening...') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'), | |
fs = require('fs'), | |
ejs = require('ejs'), | |
qs = require('querystring') | |
const settings = require('./settings') | |
const server = http.createServer() | |
const template = fs.readFileSync(`${__dirname}/views/bbs.ejs`, 'utf-8') | |
let posts = [] | |
function renderForm(posts, res) { | |
let data = ejs.render(template, { | |
posts: posts | |
}) | |
res.writeHead(200, {'Content-Type': 'text/html'}) | |
res.write(data) | |
res.end() | |
} | |
server.on('request', (req, res) => { | |
if (req.url === '/favicon.ico') { | |
return | |
} | |
if (req.url === "/css/style.css") { | |
fs.readFile('./css/style.css', 'UTF-8', (err, data) => { | |
res.writeHead(200, {'Content-Type': 'text/css'}) | |
res.write(data) | |
res.end() | |
}) | |
return | |
} | |
if (req.method === 'POST') { | |
req.data = '' | |
req.on('data', () => { | |
req.data += req.read() || '' | |
}) | |
req.on('end', () => { | |
let query = qs.parse(req.data) | |
posts.push(query.txt || 'null') | |
renderForm(posts, res) | |
}) | |
} | |
else { | |
renderForm(posts, res) | |
} | |
}) | |
server.listen(settings.port, settings.host) | |
console.log('server listening...') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
'port': 1337, | |
'host': 'localhost' | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
} | |
body { | |
margin: 0 auto; | |
font-family: Josefin\ Snas; | |
} | |
h2 { | |
text-align: center; | |
margin: 20px 0; | |
} | |
form { | |
background: #000; | |
padding: 3px; | |
position: fixed; | |
bottom: 0; | |
width: 100%; | |
} | |
form input { | |
border: 0; | |
padding: 10px; | |
width: 80%; | |
margin-right: .5%; | |
} | |
form button { | |
width: 17%; | |
background: rgb(130, 224, 255); | |
border: none; | |
padding: 10px; | |
} | |
p#msg { | |
display: none; | |
position: fixed; | |
bottom: 55px; | |
font-size: 1.5em | |
padding: 5px 20px; | |
} | |
ul { | |
list-style-type: none; | |
padding: 0; | |
margin: 10px auto 0; | |
} | |
ul li { | |
padding: 5px 10px; | |
font-size: 1.2em; | |
} | |
ul li:nth-child(odd) { | |
background: #eee; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment