Started doing client-side routing, added some rewriting on the server to support it
This commit is contained in:
parent
eec82a7dd9
commit
0b8e97b215
@ -1,9 +1,14 @@
|
||||
var React = require('react');
|
||||
var Router = require('react-router');
|
||||
var Route = Router.Route;
|
||||
var DefaultRoute = Router.DefaultRoute;
|
||||
|
||||
require('./irc');
|
||||
var socket = require('./socket');
|
||||
var util = require('./util');
|
||||
var App = require('./components/App.jsx');
|
||||
var Chat = require('./components/Chat.jsx');
|
||||
var Settings = require('./components/Settings.jsx');
|
||||
var tabActions = require('./actions/tab');
|
||||
var serverActions = require('./actions/server');
|
||||
var channelActions = require('./actions/channel');
|
||||
@ -25,4 +30,13 @@ socket.on('error', function(error) {
|
||||
console.log(error.server + ': ' + error.message);
|
||||
});
|
||||
|
||||
React.render(<App />, document.body);
|
||||
var routes = (
|
||||
<Route name="app" path="/" handler={App}>
|
||||
<Route name="settings" handler={Settings} />
|
||||
<DefaultRoute handler={Chat} />
|
||||
</Route>
|
||||
);
|
||||
|
||||
Router.run(routes, Router.HistoryLocation, function(Handler) {
|
||||
React.render(<Handler />, document.body);
|
||||
});
|
@ -1,14 +1,14 @@
|
||||
var React = require('react');
|
||||
var RouteHandler = require('react-router').RouteHandler;
|
||||
|
||||
var TabList = require('./TabList.jsx');
|
||||
var Chat = require('./Chat.jsx');
|
||||
|
||||
var App = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<div>
|
||||
<TabList />
|
||||
<Chat />
|
||||
<RouteHandler />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
13
client/src/js/components/Settings.jsx
Normal file
13
client/src/js/components/Settings.jsx
Normal file
@ -0,0 +1,13 @@
|
||||
var React = require('react');
|
||||
|
||||
var Settings = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<div>
|
||||
<h1>Settings</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = Settings;
|
2
irc.go
2
irc.go
@ -94,7 +94,7 @@ func (i *IRC) Connect(address string) error {
|
||||
}
|
||||
i.Server = address
|
||||
|
||||
dialer := &net.Dialer{Timeout: 5 * time.Second}
|
||||
dialer := &net.Dialer{Timeout: 10 * time.Second}
|
||||
|
||||
if i.TLS {
|
||||
if i.TLSConfig == nil {
|
||||
|
@ -17,7 +17,7 @@ type WSResponse struct {
|
||||
type Connect struct {
|
||||
Server string `json:"server"`
|
||||
TLS bool `json:"tls"`
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Nick string `json:"nick"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
@ -56,7 +56,7 @@ type Quit struct {
|
||||
type Chat struct {
|
||||
Server string `json:"server"`
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
To string `json:"to,omitempty"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
|
24
main.go
24
main.go
@ -3,8 +3,10 @@ package main
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"golang.org/x/net/websocket"
|
||||
|
||||
"github.com/khlieng/name_pending/storage"
|
||||
@ -14,13 +16,27 @@ var (
|
||||
channelStore *storage.ChannelStore
|
||||
sessions map[string]*Session
|
||||
sessionLock sync.Mutex
|
||||
fs http.Handler
|
||||
)
|
||||
|
||||
func serveFiles(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasSuffix(r.URL.Path, "bundle.js") {
|
||||
r.URL.Path = "/bundle.js"
|
||||
} else if strings.HasSuffix(r.URL.Path, "style.css") {
|
||||
r.URL.Path = "/style.css"
|
||||
} else {
|
||||
r.URL.Path = "/"
|
||||
}
|
||||
|
||||
fs.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func main() {
|
||||
defer storage.Cleanup()
|
||||
|
||||
channelStore = storage.NewChannelStore()
|
||||
sessions = make(map[string]*Session)
|
||||
fs = http.FileServer(http.Dir("client/dist"))
|
||||
|
||||
/*for _, user := range storage.LoadUsers() {
|
||||
channels := user.GetChannels()
|
||||
@ -49,9 +65,11 @@ func main() {
|
||||
}
|
||||
}*/
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir("client/dist")))
|
||||
http.Handle("/ws", websocket.Handler(handleWS))
|
||||
router := httprouter.New()
|
||||
|
||||
router.Handler("GET", "/ws", websocket.Handler(handleWS))
|
||||
router.NotFound = serveFiles
|
||||
|
||||
log.Println("Listening on port 1337")
|
||||
http.ListenAndServe(":1337", nil)
|
||||
http.ListenAndServe(":1337", router)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user