简体   繁体   English

Express和Node.js的登录页面

[英]Landing page with Express and nodejs

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? 如何使用nodejs和express来显示登录页面? I mean, how to redirect the client to /ios if he uses an iPhone for example. 我的意思是,例如,如果客户端使用iPhone,如何将客户端重定向到/ ios。

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中渲染静态资产的信息,请参见此处

@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/然后检查标题以确定用户来自何处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM