使用Express和nodejs登陆页面

时间:2021-07-12 12:21:25

I just bought a HTML landing page and I am totally newbie with all of this...

我刚刚买了一个HTML登陆页面,我完全是新手了...

There are 3 different folders : /windows /ios /android

有3个不同的文件夹:/ windows / ios / android

How can I use nodejs and express to display the landing page? I mean, how to redirect the client to /ios if he uses an iPhone for example.

如何使用nodejs和express来显示登录页面?我的意思是,如果他使用iPhone,如何将客户端重定向到/ ios。

2 个解决方案

#1


0  

@Detuned posted some really good links that answer your question.

@Detuned发布了一些非常好的链接来回答你的问题。

Basically, you'd want to check the userAgent and render a page based on where they're coming from.

基本上,您需要检查userAgent并根据它们的来源呈现页面。

The userAgent names aren't correct, or shouldn't be since i've not checked them but i'd expect something similar to this :

userAgent名称不正确,或者不应该是因为我没有检查它们但我希望类似于此:

app.get('/', function(req, res) {

  var userAgent = req.headers['user-agent'];

  if (userAgent.startsWith('Mozilla') || userAgent.startsWith('Chrome') || userAgent.startsWith('Explorer')) {

      res.render('index_windows', {})

  } else if (userAgent.startsWith('iOS')) {

      res.render('index_ios', {})

  } else if (userAgent.startsWith('android')) {
      res.render('index_android', {})
  }
  else {
   res.render('index_windows', {})
  }
});

This basically grabs the / which is your home url like www.example.com/ and does a check on the headers to determine where the user has come from.

这基本上抓住了/您的主页,例如www.example.com/,并检查标题以确定用户来自何处。

#2


0  

There are two ways of going about this: you would detect the browser/platform type on the client side (here) or server side (here). You would, then, send that information over to the server side so that you can render the appropriate static assets based on that information.

有两种方法可以解决这个问题:您可以在客户端(此处)或服务器端(此处)检测浏览器/平台类型。然后,您可以将该信息发送到服务器端,以便您可以根据该信息呈现适当的静态资产。

For rendering static assets in Node.js, refer here

要在Node.js中呈现静态资产,请参阅此处

#1


0  

@Detuned posted some really good links that answer your question.

@Detuned发布了一些非常好的链接来回答你的问题。

Basically, you'd want to check the userAgent and render a page based on where they're coming from.

基本上,您需要检查userAgent并根据它们的来源呈现页面。

The userAgent names aren't correct, or shouldn't be since i've not checked them but i'd expect something similar to this :

userAgent名称不正确,或者不应该是因为我没有检查它们但我希望类似于此:

app.get('/', function(req, res) {

  var userAgent = req.headers['user-agent'];

  if (userAgent.startsWith('Mozilla') || userAgent.startsWith('Chrome') || userAgent.startsWith('Explorer')) {

      res.render('index_windows', {})

  } else if (userAgent.startsWith('iOS')) {

      res.render('index_ios', {})

  } else if (userAgent.startsWith('android')) {
      res.render('index_android', {})
  }
  else {
   res.render('index_windows', {})
  }
});

This basically grabs the / which is your home url like www.example.com/ and does a check on the headers to determine where the user has come from.

这基本上抓住了/您的主页,例如www.example.com/,并检查标题以确定用户来自何处。

#2


0  

There are two ways of going about this: you would detect the browser/platform type on the client side (here) or server side (here). You would, then, send that information over to the server side so that you can render the appropriate static assets based on that information.

有两种方法可以解决这个问题:您可以在客户端(此处)或服务器端(此处)检测浏览器/平台类型。然后,您可以将该信息发送到服务器端,以便您可以根据该信息呈现适当的静态资产。

For rendering static assets in Node.js, refer here

要在Node.js中呈现静态资产,请参阅此处

相关文章