$ touch index.js server.js
$ mkdir public public/css public/js
$ touch public/home.html public/css/home.css public/js/home.js public/room.html public/css/room.css public/js/room.js
This file contains 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 Fastify = require('fastify') | |
const path = require('path') | |
const fs = require('fs') | |
const rootPath = path.resolve(__dirname, '..') | |
const fastify = Fastify({ | |
http2: true, | |
https: { |
This file contains 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 http2 = require('http2') | |
const path = require('path') | |
const fs = require('fs') | |
const rootPath = path.resolve(__dirname, '..') | |
const httpServer = http2.createSecureServer( | |
{ |
This file contains 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
// 初始化 socket | |
const socket = io(); | |
// DOM | |
const messageList = document.querySelector('.chat__list'); | |
const input = document.getElementById('newContent'); | |
const submitBtn = document.getElementById('messageCreateBtn'); | |
let uid = null; |
This file contains 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 express = require('express'); | |
const app = express(); | |
app.use(express.static(__dirname + '/public')); | |
// 簡單建立兩個 endpoint 分給兩個頁面 lobby, room | |
app.get('/', (req, res) => { | |
res.sendFile('lobby.html', { root: __dirname + '/public/' }); | |
}); |
$ npm i express socket.io -S
$ mkdir chatty // project name
$ cd chatty
$ npm init -y // init package.json
This file contains 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
// index.js | |
// This is a customized element | |
class Hello extends React.Component { | |
render() { | |
return ( | |
<div>Hello React</div> | |
); |
This file contains 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
<!-- index.html --> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>React Tutorial</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react-dom.min.js"></script> | |
</head> |