100 Commits

Author SHA1 Message Date
1f2871b917 doc: preliminary changelog update 2017-10-16 18:47:32 +13:00
855206feed hide (0) from page title 2017-10-16 18:33:43 +13:00
efa195df5b bump scrollback limit from 50->200 2017-10-16 18:30:56 +13:00
89c8cb0dc8 contented: fix upload item disappearing once logged in 2017-10-15 22:55:00 +13:00
c2de4c8d45 Added tag release-1.2.0 for changeset 0eeab5594ba4 2017-10-15 22:54:41 +13:00
738e9aed41 doc: preliminary changelog update 2017-10-15 22:06:35 +13:00
bdb7b4835d fixes for previous 2017-10-15 22:03:27 +13:00
447e8c2591 js: initial contented implementation 2017-10-15 20:56:47 +13:00
37014f7f52 server: send contented_server option down websocket to client 2017-10-15 20:56:38 +13:00
b8791f6aa2 js: rename $ -> el for jQuery compat 2017-10-15 20:56:23 +13:00
377131e43d replace menu icon from astral unicode to mini svg 2017-10-15 20:30:06 +13:00
20fa044906 whitespace 2017-10-15 20:24:56 +13:00
0cb14fb964 build: remove win64, linux32 targets 2017-10-15 20:22:15 +13:00
a60d821e39 build: expand clientpack cleanup commands 2017-10-15 20:20:52 +13:00
15d9ee0023 update uglifyjs dependency install script 2017-10-15 20:13:23 +13:00
ed0195c4b8 chmod +x 2017-10-15 20:07:26 +13:00
a71eb45dd5 Added tag release-1.1.4 for changeset 76c178b8f27e 2017-02-11 14:18:13 +13:00
086ecfb0a9 readme 2017-02-11 14:14:19 +13:00
dff36f6bff update godist 2017-02-11 14:13:58 +13:00
7a9b271b90 Added tag release-1.1.3 for changeset 6cbd9d596303 2017-02-11 13:13:27 +13:00
1c7842c182 readme 2017-02-11 13:13:09 +13:00
9e33e50986 display ip addresses 2017-02-09 19:28:43 +13:00
7f618db70a fix not displaying nonzero share sizes 2017-02-08 19:02:20 +13:00
7894355647 popups: only show when manually turning on the feature, not when it's auto-enabled on load 2017-02-08 18:34:12 +13:00
af324441b7 client: clicking the popup refocus browser window, switch to PM tab as necessary 2017-02-08 18:33:17 +13:00
d862a3f703 more consistent comment style for URL references 2017-02-08 18:20:35 +13:00
59c118dc34 remove queryselectorall, always use the fallback implementation 2017-02-08 18:19:57 +13:00
42a8298362 standardise event cancellation 2017-02-08 18:19:33 +13:00
c4e37bf47d explicit falsey checks for some persistent vars (no practical difference) 2017-02-06 16:49:37 +13:00
95d56dbca2 Added tag release-1.1.2 for changeset 7278eb0d067d 2017-02-06 16:44:27 +13:00
761d0bfad5 build: set build version in binary at build time 2017-02-06 16:43:17 +13:00
1d3f16e6c6 change default hub name in sample file 2017-02-06 16:43:07 +13:00
e5ceadb03a doc: changelog 2017-02-06 16:39:27 +13:00
6999069fd7 server: set SERVER header on all requests (even SIO ones), display version on startup 2017-02-06 16:35:25 +13:00
5da61d5922 whitespace in sample config file 2017-02-06 16:27:33 +13:00
d33ba5c085 remove 'extern' from config files 2017-02-06 16:27:14 +13:00
a28e5ce9b0 remove extra /conf/ request 2017-02-06 16:25:49 +13:00
3448cb7eeb don't require extern 2017-02-06 16:20:31 +13:00
ba941adfdd client: fix padding around user count in title 2017-02-06 13:54:24 +13:00
48d96f9efe Added tag release-1.1.1 for changeset d14041daa7bb 2017-02-06 13:46:20 +13:00
1a1f361e60 doc: changelog 2017-02-06 13:45:22 +13:00
3f1f575652 fix minifier generating malformed content 2017-02-06 13:44:56 +13:00
e2af839101 Added tag release-1.1.0 for changeset a2c92b262f33 2017-02-06 12:25:57 +13:00
659576c7e1 doc: changelog 2017-02-06 12:24:50 +13:00
0c5279e254 build: include clientpack.php in source archive 2017-02-06 12:19:05 +13:00
99cf8ebe49 custom favicon support 2017-02-06 12:18:21 +13:00
1189d6fe60 remove unused config.app.name/version 2017-02-06 12:18:07 +13:00
96c3e6ea7d remove unused key from sample config 2017-02-06 12:00:19 +13:00
1a64f79394 client: minify/combine CSS/JS/HTML via extra build step 2017-02-06 11:58:38 +13:00
692537c6f0 client/js: clearer state machine for html5 notification permissions 2017-02-06 11:58:21 +13:00
d2b1d23ba6 client/js: remove dead code (1) 2017-02-06 11:58:00 +13:00
bc80c94a6f client/socket.io: reduce size of MIT boilerplate 2017-02-06 11:57:40 +13:00
fd79d94a20 doc: preliminary changelog (2) 2017-02-05 23:11:52 +13:00
d17ad14914 doc: preliminary changelog 2017-02-05 23:10:55 +13:00
763f5030d1 client: make warn-on-close optional, default false 2017-02-05 22:47:25 +13:00
aa8d89d14b client: display unread message count in the title 2017-02-05 22:43:21 +13:00
d937491545 client: add warning popup if closing the tab while the connection is still open 2017-02-05 20:57:38 +13:00
226e6751c6 client: separate NEW vs NEW-PM titles, move user count to the end of the title 2017-02-05 20:52:24 +13:00
9060b87e94 client: 'unread' support for the main tab 2017-02-05 20:46:50 +13:00
78b7af7fbc css: add some whitespace between bottom of text and the input box 2017-02-05 20:11:10 +13:00
ff075e2e7e client: fix clearing ALL unread flags when clearing a single one 2017-02-05 20:07:28 +13:00
ef9057383d client: fixes for previous 2017-02-05 20:07:15 +13:00
0951bf821e client: page visibility detection infrastructure (but it doesn't do anything yet) 2017-02-05 19:59:43 +13:00
a60e4bb0c2 client: fix closed tabs coming back from the dead in some cases 2017-02-05 19:43:31 +13:00
7b5dbde7a6 client: add disconnected/reconnected messages into PM windows 2017-02-05 19:43:23 +13:00
3c2f0c7368 html5 notifications (disabled by default) for PMs when PM tab is not active 2017-02-05 19:35:59 +13:00
1cc6cd2b90 patch issue in r46 2017-02-05 19:09:08 +13:00
3f077f15f0 client: support shift+tab to autocomplete backward 2017-02-05 18:29:44 +13:00
ade4439f92 server: add log message on successful upstream connection 2017-02-05 18:24:32 +13:00
edffaac74b server: remove dead code 2017-02-05 18:24:22 +13:00
ceb7420e18 client: display join/parts for PM tabs (regardless of global join/part setting) 2017-02-05 18:13:45 +13:00
56ced01e97 client: clickable magnet links 2017-02-05 18:09:53 +13:00
3c1db1266e client: add noreferrer to outgoing links 2017-02-05 18:06:18 +13:00
4a4e9e694d client: custom date formats (minutes/seconds/full) 2017-02-05 18:03:44 +13:00
c619be5917 client: chat scrollback: clamp to edges rather than wrapping 2017-02-05 17:49:59 +13:00
afd190b7cc client: chat scrollback with ctrl+up / ctrl+down 2017-02-05 17:48:25 +13:00
a927add8c5 client: clearer state transitions, separate disconnected state 2017-02-05 17:35:45 +13:00
0a5db6a015 client: patch one case of not clearing userlist, set spellcheck attr when in text-entry mode 2017-02-05 17:28:35 +13:00
e15a6afceb client: automatically reconnect with same username if we lose connection to the server 2017-02-05 17:17:51 +13:00
c19b0fe521 also load stock username text when we get a reconnect page 2017-02-05 17:15:20 +13:00
1eaabb099d client: only clear the screen on first load, not on refresh 2017-02-05 17:09:18 +13:00
b26b3a695e prevent displaying sentinel pass if no pass was used 2017-02-05 17:06:58 +13:00
b30beac2b5 obfuscate saved password when re-logging in 2017-02-05 16:58:13 +13:00
39e84f2744 client: display description/email/client tag/share size on hover, display operators in green 2017-02-05 16:47:54 +13:00
7ceed88dfa server: send user details 2017-02-05 16:47:39 +13:00
c7e40ab6c1 whitespace 2017-02-05 16:14:57 +13:00
35994e81c6 drop dead code 2017-02-05 16:14:02 +13:00
2c94713ba0 persistence_set/get functions, save the join/part status 2017-02-05 16:11:52 +13:00
e9b3fedb17 save last username/pass for login 2017-02-05 16:03:43 +13:00
d0219cb16a fix superfluous nl2br 2017-02-05 15:58:19 +13:00
d0d52e931e favicon: include 256x256 32bpp in the icon 2017-02-05 15:57:09 +13:00
0ec9ae30b4 embed MIT license in socket.io JS file 2017-02-05 15:54:23 +13:00
490d20b807 bump bundled socket.io from 1.4.5 to 1.7.2 2017-02-05 15:48:59 +13:00
299a1c12e1 remove some very old pre-tab private message stuff 2017-02-05 15:43:52 +13:00
a9dc45f727 css: also support consecutive spaces in system messages 2017-02-05 15:43:16 +13:00
5f8544f031 css: fix malformed text-size-adjust parameters 2017-02-05 15:41:28 +13:00
ea87419abc css: support consecutive spaces in chat messages 2017-02-05 15:40:44 +13:00
d5e8e051e3 conf: new Web>ExternalWebroot key to load from /client/ directory 2017-02-05 15:37:27 +13:00
656125e790 conf: remove App>Debug key 2017-02-05 15:34:32 +13:00
0892666ead Added tag release-1.0.2 for changeset 46fe53368241 2016-11-29 20:19:35 +13:00
14 changed files with 845 additions and 228 deletions

View File

@@ -2,6 +2,7 @@ mode:regex
\.exe$
^nmdc-webfrontend\.conf$
^clientpack/
^_dist/
^bindata\.go$

View File

@@ -1,2 +1,9 @@
769fad81e3f8db8f7e5f5c164656a382a169d735 release-1.0.0
9ed95938d809a8226aca529e34b655e6d8c8c379 release-1.0.1
46fe533682419c8a519836ac95b5575053aa0fa8 release-1.0.2
a2c92b262f339f82eb01c8d92dda252a27432255 release-1.1.0
d14041daa7bbbd37ea2ff47aa978b9595af67ca3 release-1.1.1
7278eb0d067d8ed2a653de6a1feeeb7f76fb9891 release-1.1.2
6cbd9d59630372c0dff430e3dc6c1fbd7dcee734 release-1.1.3
76c178b8f27ec894e79b8f73649fcb3e45a73729 release-1.1.4
0eeab5594ba4d683e6a268ef971675c73b226bd0 release-1.2.0

View File

@@ -2,17 +2,17 @@ package main
type Config struct {
App struct {
Name string `json:"name"`
Version string `json:"version"`
MotdHTML string `json:"motd"`
Debug bool `json:"debug"`
MotdHTML string `json:"motd"`
ContentedServer string `json:"contented_server"`
}
Web struct {
Port int `json:"port"`
BindTo string `json:"bind_to"`
Extern string `json:"extern"`
Title string `json:"title"`
Port int `json:"port"`
BindTo string `json:"bind_to"`
Title string `json:"title"`
CustomFavicon bool `json:"custom_favicon"`
ExternalWebroot bool `json:"external_webroot,omitempty"`
}
Hub struct {

View File

@@ -8,10 +8,70 @@ Tags: nmdc
=UPGRADING FROM DCWEBUI2=
- The configuration file format is identical, but please now ensure it's valid json instead of just a .js file. This means no assignment, use double-quoted strings, and no comments.
- The configuration file content is identical between nmdc-webfrontend 1.0.0 and dcwebui2 1.3.0, but please now ensure it's valid JSON instead of arbitrary javascript. This means no assignment, use double-quoted strings, and no comments.
- Future changes to the configuration file since nmdc-webfrontend 1.0.0 are backward compatible (see the changelog for more details).
=CHANGELOG=
2017-10-16 1.2.1
- Enhancement: Increase scrollback buffer size
- Fix an issue with missing `contented` upload link once logged in
- Fix a cosmetic issue with `(0)` appearing in page title
2017-10-15 1.2.0
- Feature: Add `contented` integration (set `app.contented_server` in config file)
- Fix a cosmetic issue with the menu icon on devices without unicode font coverage
2017-02-11 1.1.4
- Update libnmdc to 0.14
2017-02-11 1.1.3
- Feature: Display user IP address on hover, if available
- Enhancement: Allow clicking on popup notifications
- Enhancement: Only show 'popups enabled' notification when enabling for the first time, not persistent page load
- Update libnmdc to 0.13
- Fix a cosmetic issue with not displaying non-zero user share sizes
2017-02-06 1.1.2
- Autodetect 'extern', no need to include it in config files
- Enhancement: Remove redundant request, for a faster page load
- Display server version number in log file and in response headers
- Fix a cosmetic issue with spacing around user count in page title
2017-02-06 1.1.1
- Fix an issue with malformed content in minified build
2017-02-06 1.1.0
- Feature: Remember last username/password for login; remember last "show joins/parts" status
- Feature: Display user details on hover (description, email, client tag, share size)
- Feature: Optional desktop notifications for background PMs (not possible in incognito)
- Feature: Automatically reconnect with the same username/password if connection was lost
- Feature: Re-enter last message (Ctrl+Up, Ctrl+Down)
- Feature: Set custom date/time format (Minutes, Seconds, Full), remembered for next session
- Feature: Clickable magnet links
- Feature: Display unread main-chat message count in the page title if the window is inactive
- Feature: Add warning message when closing tab while still connected (optional preference, disabled by default, will be remembered).
- Feature: Admin option to load a custom favicon (set `web.custom_favicon=true` and place a `favicon.ico` in the current directory)
- Feature: Admin option to use external web resources (set `web.external_webroot=true` and use the /client/ directory)
- Enhancement: Higher resolution favicon
- Enhancement: Display operators in green in the user list
- Enhancement: Enable spellcheck for text input once logged in
- Enhancement: Prevent sending referrer to remote URLs
- Enhancement: Display joins/parts and connection/disconnection messages in PM tabs
- Enhancement: Support Shift+Tab to autocomplete backward
- Enhancement: Support unread status for the main tab
- Enhancement: Improve page load time via minification
- Remove unused options from the config file
- Update socket.io to 1.7.2
- Update libnmdc to 0.12
- Add margin between bottom of the text area and the text input box
- Fix a cosmetic issue with collapsing consecutive spaces in posted messages
- Fix a cosmetic issue with text size adjustment on mobile devices
- Fix a cosmetic issue with clearing the screen on reconnection
- Fix a cosmetic issue with not clearing the userlist on certain types of network error
- Fix a cosmetic issue with closed PM tabs reappearing in some cases
- Fix a cosmetic issue with marking all PM tabs as read when switching to a single one
2016-11-29 1.0.2
- Rebuild with libnmdc 0.11
- Fix an issue with not setting a version in the client tag

14
build.sh Normal file → Executable file
View File

@@ -86,11 +86,13 @@ single_build() {
# Build.
# GOARCH/GOOS supplied in function env
local gofwdpath=$(echo -n $GOPATH | sed 's/[\\/]$//')
go build \
-a \
-ldflags '-s -w' \
-gcflags "-trimpath=${GOPATH}" \
-asmflags "-trimpath=${GOPATH}" \
-ldflags "-s -w -X main.VERSION=nmdc-webfrontend/${version}" \
-gcflags "-trimpath ${gofwdpath}" \
-asmflags "-trimpath ${gofwdpath}" \
-o "$(pathfix "${tmpdir}/${local_bin_name}")"
# Archive.
@@ -158,18 +160,18 @@ main() {
if [[ -f ./bindata.go ]] ; then
rm ./bindata.go
fi
go-bindata -nomemcopy -prefix client client
php clientpack.php
go-bindata -nomemcopy -prefix clientpack clientpack
GOARCH=amd64 GOOS=windows single_build "$version"
GOARCH=386 GOOS=windows single_build "$version"
GOARCH=amd64 GOOS=linux single_build "$version"
GOARCH=386 GOOS=linux single_build "$version"
# Also make source tarball
local SOURCE_FILES=(
client/
build.sh
clientpack.php
Config.go
main.go
nmdc-webfrontend.conf.SAMPLE

View File

@@ -1,9 +1,9 @@
/* dcwebui.css */
* {
-webkit-text-size-adjust:100%
-moz-text-size-adjust:100%
-ms-text-size-adjust:100%
-webkit-text-size-adjust:100%;
-moz-text-size-adjust:100%;
-ms-text-size-adjust:100%;
}
html,body {
@@ -71,10 +71,15 @@ html,body {
color:black;
font-weight:bold;
line-height:18px;
line-height:0;
height:18px;
width:18px;
text-align:center;
}
.menubutton svg {
width: 18px;
height: 18px;
}
.menubutton:hover {
background:white;
}
@@ -180,13 +185,13 @@ html,body {
overflow-y:auto;
-webkit-transition: all 0.25s ease-in-out;
padding:0; /*4px;*/
padding:0;
margin:0;
box-sizing:border-box;
position:absolute;
top:4px;
bottom:0;
bottom:4px;
left:4px;
right:0;
}
@@ -300,6 +305,9 @@ html,body {
/* Text */
.tx-sys, .tx-user, .tx-chat {
white-space:pre-wrap;
}
.tx-time {
color:grey;
}
@@ -314,10 +322,6 @@ html,body {
.tx-chat {
color: black;
}
.tx-private {
color: red;
font-style: italic;
}
/* webkit scrollbars */
@@ -354,6 +358,11 @@ html,body {
overflow-y: auto;
}
.user-is-operator {
color:darkgreen;
font-weight:bold;
}
/* User sprite */
.ul-mini {
@@ -393,4 +402,4 @@ html,body {
.position-panel {
display:block;
}
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -6,13 +6,17 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="stylesheet" href="/dcwebui.css">
<link rel="stylesheet" href="/dcwebui.css">
<title>Loading...</title>
</head>
<body>
<div class="tabbar placement-top" id="bar">
<div class="menubutton" id="menubutton">&#9776;</div>
<div class="tabitem selected" data-tab="tab-main">
<div class="menubutton" id="menubutton">
<svg viewBox="0 0 24 24">
<path fill="#000000" d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" />
</svg>
</div>
<div class="tabitem selected" data-tab="tab-main" id="tabitem-tab-main">
<span class="tab-label">
Main
</span>
@@ -52,8 +56,7 @@
</form>
</div>
<script type="text/javascript" src="/socket.io-1.4.5.js"></script>
<script type="text/javascript" src="/conf"></script>
<script type="text/javascript" src="/socket.io-1.7.2.js"></script>
<script type="text/javascript" src="/dcwebui.js"></script>
</body>
</html>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

60
clientpack.php Executable file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/php
<?php
# Dependencies:
# - PHP
# - Uglifyjs (`npm install -g uglify-js`)
# - Lessc (`npm install -g less`)
# - Lessc minifier (`npm install -g less-plugin-clean-css`)
# - HTML minifier (`npm install -g html-minifier`)
echo "Compressing/minifying web resources...\n";
if (is_dir('clientpack')) {
`rm -r clientpack`;
}
`cp -r client clientpack`;
// Toggle IIFE on
`sed -i -re 's~//IIFEMODE:~~g' clientpack/dcwebui.js`;
// Minify JS
`uglifyjs clientpack/dcwebui.js -o clientpack/dcwebui.min.js -c -m`;
// Minify CSS
`lessc --clean-css clientpack/dcwebui.css clientpack/dcwebui.min.css`;
// Embed css into HTML file
$html_content = file_get_contents('clientpack/index.htm');
$html_content = preg_replace_callback('~<link[^>]+dcwebui.css[^>]*>~', function() { return '<style type="text/css">'.file_get_contents('clientpack/dcwebui.min.css').'</style>'; }, $html_content);
// Embed JS into HTML file
$html_content = preg_replace_callback('~<script[^>]+dcwebui.js[^>]*>~', function() { return '<script type="text/javascript">'.file_get_contents('clientpack/dcwebui.min.js').'</script>'; }, $html_content);
// Embed socketio into HTML file
define('SIO_NAME', 'socket.io-1.7.2.js');
$html_content = preg_replace_callback('~<script[^>]+'.SIO_NAME.'[^>]*>~', function() { return '<script type="text/javascript">'.file_get_contents('clientpack/'.SIO_NAME).'</script>'; }, $html_content);
// Minify the combined file
file_put_contents('clientpack/index.htm', $html_content);
`html-minifier --collapse-whitespace -o clientpack/index.min.htm clientpack/index.htm`;
// Clean up files
unlink('clientpack/index.htm');
unlink('clientpack/dcwebui.js');
unlink('clientpack/dcwebui.min.js');
unlink('clientpack/dcwebui.css');
unlink('clientpack/dcwebui.min.css');
unlink('clientpack/'.SIO_NAME);
rename('clientpack/index.min.htm', 'clientpack/index.htm');

97
main.go
View File

@@ -12,10 +12,7 @@ import (
"github.com/googollee/go-socket.io"
)
type ActiveConnection struct {
s *socketio.Socket
h *libnmdc.HubConnection
}
var VERSION string = `nmdc-webfrontend/devel-unreleased`
type App struct {
cfg *Config
@@ -81,6 +78,29 @@ func (this *App) HubWorker(Nick, Pass string, so socketio.Socket, done chan stru
// Loop hub connection
serveUserInfo := func(nick string) {
props := ""
hub.Users(func(users *map[string]libnmdc.UserInfo) error {
uinfo, ok := (*users)[nick]
if !ok {
return nil // just skip
}
bProps, err := json.Marshal(uinfo)
if err != nil {
return nil // just skip
}
props = string(bProps)
return nil
})
// 'Message' is a json-encoded param with user properties
if len(props) > 0 {
so.Emit("info", UserMessageStruct{User: nick, Message: props})
}
}
for {
select {
@@ -100,14 +120,19 @@ func (this *App) HubWorker(Nick, Pass string, so socketio.Socket, done chan stru
case libnmdc.EVENT_PRIVATE:
so.Emit("priv", UserMessageStruct{User: hev.Nick, Message: hev.Message})
case libnmdc.EVENT_USER_UPDATED_INFO:
serveUserInfo(hev.Nick)
case libnmdc.EVENT_USER_JOINED:
so.Emit("join", UserMessageStruct{User: hev.Nick})
serveUserInfo(hev.Nick)
case libnmdc.EVENT_USER_PART:
so.Emit("part", UserMessageStruct{User: hev.Nick})
case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
if hev.StateChange == libnmdc.CONNECTIONSTATE_CONNECTED {
log.Printf("[%s] Connected to hub\n", so.Id())
so.Emit("hello")
} else if hev.StateChange == libnmdc.CONNECTIONSTATE_DISCONNECTED {
so.Emit("close")
@@ -126,11 +151,6 @@ func (this *App) HubWorker(Nick, Pass string, so socketio.Socket, done chan stru
"raw": hev.UserCommand.Command,
})
default:
if this.cfg.App.Debug {
log.Printf("[%s] %v\n", so.Id(), hev)
}
}
case <-done:
@@ -146,9 +166,14 @@ func (this *App) SocketIOServer(so socketio.Socket) {
log.Printf("[%s] Client connected", so.Id())
so.Emit("cls")
so.Emit("hubname", this.cfg.Web.Title)
so.Emit("raw", this.cfg.App.MotdHTML+"<br>")
so.Emit("sys", "Enter a name to connect as (or name:pass for a registered nick)")
if len(this.cfg.App.ContentedServer) > 0 {
so.Emit("contented", this.cfg.App.ContentedServer)
}
doneChan := make(chan struct{}, 0)
so.On("hello", func(data map[string]string) {
@@ -163,22 +188,8 @@ func (this *App) SocketIOServer(so socketio.Socket) {
}
func (this *App) ConfigRequestHandler(w http.ResponseWriter, r *http.Request) {
confStruct := struct {
Extern string `json:"extern"`
Title string `json:"title"`
}{
Extern: this.cfg.Web.Extern,
Title: this.cfg.Web.Title,
}
confBytes, _ := json.Marshal(confStruct)
//
w.Header().Set("Content-Type", "text/javascript")
w.WriteHeader(200)
fmt.Fprintf(w, "var DCWEBUI_CONF = %s;\n", string(confBytes))
func (this *App) customFaviconHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "favicon.ico")
}
func (this *App) StaticRequestHandler(w http.ResponseWriter, r *http.Request) {
@@ -195,9 +206,9 @@ func (this *App) StaticRequestHandler(w http.ResponseWriter, r *http.Request) {
knownContentTypes := map[string]string{
".htm": "text/html",
".css": "text/css",
".js": "application/javascript",
".png": "image/png",
".ico": "image/x-icon",
// No CSS/JS since they're embedded in the HTML
}
foundMime := false
@@ -219,6 +230,9 @@ func (this *App) StaticRequestHandler(w http.ResponseWriter, r *http.Request) {
func (this *App) RunServer() {
// Inner mux {{
innerMux := http.NewServeMux()
// Socket.io handler
server, err := socketio.NewServer(nil)
if err != nil {
@@ -228,22 +242,39 @@ func (this *App) RunServer() {
server.On("error", func(so socketio.Socket, err error) {
log.Println("error:", err)
})
http.Handle("/socket.io/", server)
innerMux.Handle("/socket.io/", server)
// Configuration handler
http.HandleFunc("/conf", this.ConfigRequestHandler)
// Custom favicon handler
if this.cfg.Web.CustomFavicon {
innerMux.HandleFunc("/favicon.ico", this.customFaviconHandler)
}
// Other files: asset handler
http.HandleFunc("/", this.StaticRequestHandler)
// Asset handler
if this.cfg.Web.ExternalWebroot {
innerMux.Handle("/", http.FileServer(http.Dir("client")))
} else {
innerMux.HandleFunc("/", this.StaticRequestHandler)
}
// }}
// Wrapper mux {{
outerMux := http.NewServeMux()
outerMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Server", VERSION)
innerMux.ServeHTTP(w, r)
})
// }}
// Listen and serve
bindAddr := fmt.Sprintf("%s:%d", this.cfg.Web.BindTo, this.cfg.Web.Port)
log.Printf("Serving at %s...", bindAddr)
log.Fatal(http.ListenAndServe(bindAddr, nil))
log.Fatal(http.ListenAndServe(bindAddr, outerMux))
}
func main() {
log.Println(VERSION)
a, err := NewApp("nmdc-webfrontend.conf")
if err != nil {
log.Fatal(err.Error())

View File

@@ -1,23 +1,20 @@
{
"app": {
"name" : "DCWebUI2",
"version": "1.3.0",
"motd" : "Welcome!<br>",
"debug" : true
"motd": "Welcome!<br>"
},
"web": {
"port" : 8082,
"port": 8082,
"bind_to": "127.0.0.1",
"extern" : "http://127.0.0.1:8082",
"title" : "DCWebUI"
"title": "NMDC Web Frontend",
"custom_favicon": false
},
"hub": {
"address": "127.0.0.1",
"port" : 411,
"tag" : "nmdc-webfrontend"
"port": 411,
"tag": "nmdc-webfrontend"
}
}