Skip to content

Commit

Permalink
Define $is_mobile / $is_desktop based on simple UA matching
Browse files Browse the repository at this point in the history
  • Loading branch information
amcclain committed Sep 20, 2019
1 parent 3d2c505 commit 9a93d53
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions xh.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ map $sent_http_content_type $expires {
# Increase client max body size to allow for larger uploads
client_max_body_size 20m;

# Set $is_desktop and $is_mobile variables for simple UA-based sniffing.
# This was snagged from https://gist.github.com/perusio/1326701 and is not guaranteed by any means
# to be perfect or exhaustive. Apps should use with care - we can tune if we have real-world cases
# where we find this is not working as desired.
map $http_user_agent $is_desktop {
default 0;
~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule
~*spider|crawl|slurp|bot 1; # bots
~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes
}

map $is_desktop $is_mobile {
1 0;
0 1;
}

# App-level Dockerfiles must copy in an appropriate conf with server directives such as the below.

#server {
Expand Down

0 comments on commit 9a93d53

Please sign in to comment.