How nodejs loads different front-end files according to different devices

the front end of the project is divided into the mobile side and the PC side, and then there are two files dist1 and dist2
now the nodejs used in the back end and the mobile side and the pc side share a set of back end codes
when originally only the PC side is used, nodejs specifies the static file

through the following code
app.use(express.static(path.join(__dirname, "../dist")))

now you want to determine whether it is mobile orPC by nodejs, and then specify dist1, mobile dist2 by pc. How can this be achieved?

the update can determine whether it is pc or mobile by the following code,

app.all("*", (req, res, next) => {
  const TYPE = req.headers["user-agent"].toLowerCase()
  // console.log(TYPE)
  const IS_MOBILE = TYPE.indexOf("android") > -1 || TYPE.indexOf("ios") > -1
  if (IS_MOBILE) {
    console.log("mobile")
    app.use(express.static(path.join(__dirname, "../dist2")))
  } else {
    console.log("pc")
    app.use(express.static(path.join(__dirname, "../dist")))
  }
  next()
})

but it brings a question, that is, after the first visit on the PC side, whether to use the mobile side to access the front-end resources of the PC side or to access the front-end resources on the PC side. After the first visit by the mobile terminal, the resources of the mobile terminal are accessed by the pc side later. Is it the caching problem of node?

Oct.22,2021


nginx <br>nginx

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  www.hellomrbigbigshot.xyz;
    if ($http_host !~ "^www.hellomrbigbigshot.xyz$") {
       rewrite  ^(.*)    http://www.hellomrbigbigshot.xyz$1 permanent;
    }
    if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
      rewrite  ^(.*)    http://m.hellomrbigbigshot.xyz$1 permanent;
    }

    -sharp Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
      root /var/www/pc;
      index index.html;
      try_files $uri $uri/ /index.html;
    }
    location /api {
      rewrite  ^/apis/(.*)$ /$1 break;
      proxy_pass http://xxx.xx.xxx.xx:8081/api;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}
server {
  listen       80;
  server_name  m.hellomrbigbigshot.xyz;
  if ($http_user_agent !~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
      rewrite  ^(.*)    http://www.hellomrbigbigshot.xyz$1 permanent;
  }

  location / {
    root /var/www/mobile;
    index index.html;
    try_files $uri $uri/ /index.html;
  }
  location /api {
    rewrite  ^/apis/(.*)$ /$1 break;
    proxy_pass http://xxx.xx.xxx.xx:8081/api;
  }
  error_page 404 /404.html;
      location = /40x.html {
  }

  error_page 500 502 503 504 /50x.html;
      location = /50x.html {
  }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4c1e7-4d226.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4c1e7-4d226.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?