Web front for my code


Awhile ago I set up my own git server. I’ve been hacking happily using that and Eclipse. In my spare time, I’ve been taking UCSD’s wonderful algorithm course: Algorithmic Design and Techniques. The course provides plenty of programming challenges! I chose the paid version so my code can be evaluated against all tests in the grading server. I solved the programming challenges in 3 languages: Java, Python, and C++. It has been so much fun!

Anyway, I thought it’d be nice to enable a web front end to my own code hosted on my own server. There are a lot of choices: gitweb, gitlab, gitea, etc. A couple of days ago I came across cgit. It’s pretty lightweight, written in C. That’s what I chose for that task. It’s setup now already, please go to https://code.haidongji.com to check it out!

It takes a bit of work to get the clean subdomain working. My environment is Debian 9 running apache2. Below were steps taken to make my environment work. Hope it helps somebody!

  • sudo apt install cgit
    The install creates /etc/cgitrc file and /etc/apache2/conf-available/cgit.conf
  • Here is the content of my apache2 site conf file
    [code language=”text”]
    <VirtualHost *:80>
    ServerName code.haidongji.com
    ServerAdmin emailAddress
    DocumentRoot /usr/share/cgit/
    <Directory "/usr/share/cgit/">
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
    </Directory>
    Alias /cgit-css/cgit.css /usr/share/cgit/cgit.css
    Alias /cgit-css/cgit.png /usr/share/cgit/cgit.png
    ScriptAlias / /usr/lib/cgit/cgit.cgi/

    ErrorLog ${APACHE_LOG_DIR}/codehaidongji.log
    CustomLog ${APACHE_LOG_DIR}/codehaidongji.log combined

    </VirtualHost>[/code]

  • sudo apt install python3-pygments for syntax highlighting
  • Here is the content of the /etc/cgitrc file
    [code language=”text”]
    css=/cgit-css/cgit.css
    logo=/cgit-css/cgit.png

    # enable Pygments syntax highlighting. Must be above scan-path, otherwise it would not work!
    source-filter=/usr/lib/cgit/filters/syntax-highlighting.py
    scan-path=/srv/git[/code]

  • sudo a2enmod cgid
    sudo a2enconf cgit
  • sudo systemctl restart apache2

Note that in /etc/cgitrc, syntax highlighting line MUST BE ABOVE the scan-path line, otherwise syntax highlighting will not work!

Cheers and happy coding!

, ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.