Skip to content

Contest

Adrien Wu edited this page Sep 1, 2023 · 8 revisions

In TIOJ, each contest has a normal contest page and a Single Contest page. To access the Single Contest page, click the Go to Single Contest page button on the contest's index page. The Single Contest page differs from the normal contest page in several ways:

  • Each Single Contest page uses independent user sessions. That is, the login status within the current Single Contest page remains unaffected by any login/logout activities on the main website or on other Single Contest pages.
  • Only registered users and contest users (contest-specific batch-generated users that cannot login to the main website) of the contest can login.
    • If the name of a contest user clashes with a registered user, the registered user won't be able to log in to the Single Contest page. A warning will be displayed next to the user's profile on the Users & Registrations page.

The Single Contest page is designed to be easily proxied by a webserver such as NGINX or Apache, allowing one to easily setup a standalone website for any given contest. This can be useful in competition settings, where the primary website can serve as an internal platform (and can be protected by a firewall), and the proxied Single Contest page can be made public for contestants' access.

Here is an example NGINX configuration to proxy the Single Contest page of contest #42 to http://127.0.0.1:30080:

server {
  listen 30080;
  server_name localhost;
  location ~ ^/(assets|fonts|images|robots.txt) {
    # static files required for the website to work
    # if other assets is used in the contest, modify the pattern above accordingly
    root /home/tioj/tioj/public;
  }
  location / { # proxy
    proxy_pass http://127.0.0.1/single_contest/42/; # contest ID
    proxy_redirect ~/single_contest/42/(.*)$ /$1;   # contest ID
    proxy_redirect ~/single_contest/42$ /;          # contest ID
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto http;
  }
  location /mathjax { # MathJax is served through Rails
    proxy_pass http://127.0.0.1;
  }
  location /cable { # ActionCable
    proxy_pass http://127.0.0.1;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header SINGLECONTESTID "42"; # contest ID
  }
}

Proxy any contest by changing the 42 to the real contest ID in the lines marked # contest ID. The contest ID can be obtained from the URL (http://example.com/contest/42).

Clone this wiki locally