Skip to content

Commit

Permalink
Changes to static file serving
Browse files Browse the repository at this point in the history
- /static/custom.css is now located at /config/custom.css
- /static/avatars/ is now located at /config/avatars/
- The redirect script now redirects all room URIs, not just the root
  path. For example, if you are running a server on localhost port 8000,
  visiting http://localhost:8000/teambuilder will now take you to the
  teambuilder. This works for any room.
  • Loading branch information
cathyjf committed Apr 25, 2013
1 parent 6a61871 commit f454177
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
/node_modules
npm-debug.log
/config/bannedwords.txt
/static/custom.css
/static/avatars/

# boilerplate #
###############
Expand Down
21 changes: 18 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,28 @@ if (config.protocol === 'io') {
app = require('http').createServer();
try {
var nodestatic = require('node-static');
var fileserver = new nodestatic.Server('./static');
var cssserver = new nodestatic.Server('./config');
var avatarserver = new nodestatic.Server('./config/avatars');
var staticserver = new nodestatic.Server('./static');
app.on('request', function(request, response) {
request.resume();
request.addListener('end', function() {
fileserver.serve(request, response, function(e, res) {
var server;
if (request.url === '/custom.css') {
server = cssserver;
} else if (request.url.substr(0, 9) === '/avatars/') {
request.url = request.url.substr(8);
server = avatarserver;
} else {
if (/^\/(teambuilder|ladder|lobby|battle)\/?$/.test(request.url) ||
/^\/(lobby|battle)-([A-Za-z0-9-]*)$/.test(request.url)) {
request.url = '/';
}
server = staticserver;
}
server.serve(request, response, function(e, res) {
if (e && (e.status === 404)) {
fileserver.serveFile('404.html', 404, {}, request, response);
staticserver.serveFile('404.html', 404, {}, request, response);
}
});
});
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion config/config-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ exports.herokuhack = false;

// Custom avatars.
// This allows you to specify custom avatar images for users on your server.
// Place custom avatar files under the /static/avatars/ directory.
// Place custom avatar files under the /config/avatars/ directory.
// Users must be specified as userids -- that is, you must make the name all
// lowercase and remove non-alphanumeric characters.
//
Expand Down
9 changes: 9 additions & 0 deletions config/custom-example.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Custom CSS declarations
*
* If your server is registered, you can create a file named `custom.css`
* in the `config` directory and populate it with CSS rules to override the
* normal client styles, when the client is connected to your server. In
* other words, you can use this facility to introduce a custom theme for
* your server.
*/
8 changes: 0 additions & 8 deletions static/custom-example.css

This file was deleted.

2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<script>
var suffix = (document.location.port != '8000' ? '-' + (document.location.port || '80') : '');
document.location.replace('http://' + document.location.hostname + suffix + '.psim.us');
document.location.replace('http://' + document.location.hostname + suffix + '.psim.us' + document.location.pathname);
</script>
<p>This is a <a href="http://www.pokemonshowdown.com">Pokemon Showdown</a> server!</p>
<noscript><p>Try enabling JavaScript to play!</p></noscript>

0 comments on commit f454177

Please sign in to comment.