Update client dependencies, embed only gzipped assets and unzip on the fly if needed
This commit is contained in:
parent
c4ac9f782c
commit
5a535cf53e
|
@ -24,13 +24,13 @@ if (argv.production) {
|
|||
}
|
||||
|
||||
gulp.task('html', function() {
|
||||
gulp.src('src/*.html')
|
||||
return gulp.src('src/*.html')
|
||||
.pipe(minifyHTML())
|
||||
.pipe(gulp.dest('dist'));
|
||||
});
|
||||
|
||||
gulp.task('css', function() {
|
||||
gulp.src(['src/css/fontello.css', 'src/css/style.css'])
|
||||
return gulp.src(['src/css/fontello.css', 'src/css/style.css'])
|
||||
.pipe(concat('bundle.css'))
|
||||
.pipe(autoprefixer())
|
||||
.pipe(minifyCSS())
|
||||
|
@ -75,34 +75,30 @@ function js(watch) {
|
|||
}
|
||||
|
||||
gulp.task('fonts', function() {
|
||||
gulp.src('src/font/*')
|
||||
return gulp.src('src/font/*')
|
||||
.pipe(gulp.dest('dist/font'));
|
||||
});
|
||||
|
||||
gulp.task('gzip', ['html', 'css', 'js', 'fonts'], function() {
|
||||
gulp.src('dist/**/!(*.gz)')
|
||||
return gulp.src('dist/**/!(*.gz)')
|
||||
.pipe(gzip())
|
||||
.pipe(gulp.dest('dist'));
|
||||
.pipe(gulp.dest('dist/gz'));
|
||||
});
|
||||
|
||||
function bindata(cb) {
|
||||
if (argv.production) {
|
||||
exec('go-bindata -nomemcopy -pkg server -o ../server/bindata.go dist/...', function(err) {
|
||||
cb(err);
|
||||
});
|
||||
exec('go-bindata -nomemcopy -nocompress -pkg server -o ../server/bindata.go dist/gz/...', cb);
|
||||
} else {
|
||||
exec('go-bindata -debug -pkg server -o ../server/bindata.go dist/...', function(err) {
|
||||
cb(err);
|
||||
});
|
||||
exec('go-bindata -debug -pkg server -o ../server/bindata.go dist/...', cb);
|
||||
}
|
||||
}
|
||||
|
||||
gulp.task('bindata', ['html', 'css', 'js', 'fonts', 'gzip'], function(cb) {
|
||||
gulp.task('bindata', ['gzip'], function(cb) {
|
||||
bindata(cb);
|
||||
});
|
||||
|
||||
gulp.task('gzip:watch', function() {
|
||||
gulp.src('dist/**/*.{html,css,js}')
|
||||
return gulp.src('dist/**/*.{html,css,js}')
|
||||
.pipe(gzip())
|
||||
.pipe(gulp.dest('dist'));
|
||||
});
|
||||
|
|
|
@ -9,23 +9,25 @@
|
|||
"vinyl-source-stream": "~1.0.0",
|
||||
"gulp-if": "~1.2.5",
|
||||
"gulp": "~3.8.10",
|
||||
"gulp-uglify": "~1.0.2",
|
||||
"gulp-minify-css": "~0.3.11",
|
||||
"gulp-uglify": "1.2.0",
|
||||
"gulp-minify-css": "1.1.1",
|
||||
"gulp-streamify": "0.0.5",
|
||||
"gulp-minify-html": "~0.1.8",
|
||||
"watchify": "~2.2.1",
|
||||
"browserify": "~8.0.3",
|
||||
"gulp-autoprefixer": "~2.0.0",
|
||||
"gulp-minify-html": "1.0.2",
|
||||
"watchify": "3.2.1",
|
||||
"browserify": "10.2.0",
|
||||
"gulp-autoprefixer": "2.2.0",
|
||||
"gulp-gzip": "0.0.8",
|
||||
"babelify": "~5.0.3",
|
||||
"gulp-concat": "~2.5.2"
|
||||
"babelify": "6.1.0",
|
||||
"gulp-concat": "~2.5.2",
|
||||
"reactify": "^1.1.1",
|
||||
"del": "^1.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": "3.2.0",
|
||||
"reflux": "0.2.5",
|
||||
"react-router": "0.12.0",
|
||||
"react": "0.12.2",
|
||||
"react-infinite": "0.2.3",
|
||||
"lodash": "3.8.0",
|
||||
"reflux": "0.2.7",
|
||||
"react-router": "0.13.3",
|
||||
"react": "0.13.3",
|
||||
"react-infinite": "0.3.4",
|
||||
"autolinker": "khlieng/Autolinker.js"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ var EventEmitter = require('events').EventEmitter;
|
|||
|
||||
class Socket extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.ws = new WebSocket('ws://' + window.location.host + '/ws');
|
||||
|
||||
this.ws.onopen = () => this.emit('connect');
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,37 +0,0 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type BindataFileSystem struct{}
|
||||
|
||||
func (f BindataFileSystem) Open(name string) (http.File, error) {
|
||||
path := "dist" + name
|
||||
|
||||
data, err := Asset(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &BindataFile{bytes.NewReader(data), path}, nil
|
||||
}
|
||||
|
||||
type BindataFile struct {
|
||||
*bytes.Reader
|
||||
path string
|
||||
}
|
||||
|
||||
func (f *BindataFile) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *BindataFile) Readdir(count int) ([]os.FileInfo, error) {
|
||||
return make([]os.FileInfo, 0), nil
|
||||
}
|
||||
|
||||
func (f *BindataFile) Stat() (os.FileInfo, error) {
|
||||
return AssetInfo(f.path)
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
@ -17,8 +20,15 @@ var (
|
|||
channelStore *storage.ChannelStore
|
||||
sessions map[string]*Session
|
||||
sessionLock sync.Mutex
|
||||
fs http.Handler
|
||||
files []File
|
||||
|
||||
files = []File{
|
||||
File{"/bundle.js", "text/javascript"},
|
||||
File{"/bundle.css", "text/css"},
|
||||
File{"/font/fontello.eot", "application/vnd.ms-fontobject"},
|
||||
File{"/font/fontello.svg", "image/svg+xml"},
|
||||
File{"/font/fontello.ttf", "application/x-font-ttf"},
|
||||
File{"/font/fontello.woff", "application/font-woff"},
|
||||
}
|
||||
|
||||
upgrader = websocket.Upgrader{
|
||||
ReadBufferSize: 1024,
|
||||
|
@ -39,16 +49,6 @@ func Run(port int) {
|
|||
|
||||
channelStore = storage.NewChannelStore()
|
||||
sessions = make(map[string]*Session)
|
||||
fs = http.FileServer(BindataFileSystem{})
|
||||
|
||||
files = []File{
|
||||
File{"/bundle.js", "text/javascript"},
|
||||
File{"/bundle.css", "text/css"},
|
||||
File{"/font/fontello.eot", "application/vnd.ms-fontobject"},
|
||||
File{"/font/fontello.svg", "image/svg+xml"},
|
||||
File{"/font/fontello.ttf", "application/x-font-ttf"},
|
||||
File{"/font/fontello.woff", "application/font-woff"},
|
||||
}
|
||||
|
||||
reconnect()
|
||||
|
||||
|
@ -72,33 +72,36 @@ func upgradeWS(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func serveFiles(w http.ResponseWriter, r *http.Request) {
|
||||
var ext string
|
||||
|
||||
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||
w.Header().Set("Content-Encoding", "gzip")
|
||||
ext = ".gz"
|
||||
}
|
||||
|
||||
if r.URL.Path == "/" {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
r.URL.Path = "/index.html" + ext
|
||||
fs.ServeHTTP(w, r)
|
||||
serveFile("dist/gz/index.html.gz", "text/html", w, r)
|
||||
return
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
if strings.HasSuffix(r.URL.Path, file.Path) {
|
||||
w.Header().Set("Content-Type", file.ContentType)
|
||||
r.URL.Path = file.Path + ext
|
||||
fs.ServeHTTP(w, r)
|
||||
serveFile("dist/gz"+file.Path+".gz", file.ContentType, w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
r.URL.Path = "/index.html" + ext
|
||||
serveFile("dist/gz/index.html.gz", "text/html", w, r)
|
||||
}
|
||||
|
||||
fs.ServeHTTP(w, r)
|
||||
func serveFile(path, contentType string, w http.ResponseWriter, r *http.Request) {
|
||||
data, _ := Asset(path)
|
||||
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
|
||||
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||
w.Header().Set("Content-Encoding", "gzip")
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(data)))
|
||||
w.Write(data)
|
||||
} else {
|
||||
gzr, _ := gzip.NewReader(bytes.NewReader(data))
|
||||
buf, _ := ioutil.ReadAll(gzr)
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(buf)))
|
||||
w.Write(buf)
|
||||
}
|
||||
}
|
||||
|
||||
func reconnect() {
|
||||
|
|
Loading…
Reference in New Issue