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
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?