Skip to content

Instantly share code, notes, and snippets.

const Fastify = require('fastify')
const path = require('path')
const fs = require('fs')
const rootPath = path.resolve(__dirname, '..')
const fastify = Fastify({
http2: true,
https: {
const http2 = require('http2')
const path = require('path')
const fs = require('fs')
const rootPath = path.resolve(__dirname, '..')
const httpServer = http2.createSecureServer(
{
@hieven
hieven / lobby.js
Last active September 4, 2016 10:32
// 初始化 socket
const socket = io();
// DOM
const messageList = document.querySelector('.chat__list');
const input = document.getElementById('newContent');
const submitBtn = document.getElementById('messageCreateBtn');
let uid = null;
@hieven
hieven / server.js
Last active September 4, 2016 10:27
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/' });
});
$ 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
$ npm i express socket.io -S
$ mkdir chatty // project name
$ cd chatty 
$ npm init -y // init package.json
// index.js
// This is a customized element
class Hello extends React.Component {
render() {
return (
<div>Hello React</div>
);
<!-- 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>