Https createServer,加载cookie并加载客户端index.html [英] Https createServer, load cookie and load clients index.html

查看:132
本文介绍了Https createServer,加载cookie并加载客户端index.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在网站上设置登录系统.

I am trying to setup a login system on a website.

为此,我必须加载仅HTTP cookie.

In order to do that, I have to load http only cookies.

为了加载它们,我必须在https启动时通过createServer函数中的响应对象将它们发送回客户端.

In order to load them, I have to send them back to the client via the response object in the createServer function when https starts up.

我已经通过此处成功完成了此操作: 在nodejs中设置https cookie

I have successfully done that via here: setting up https cookie in nodejs

问题是双重的.

  1. 仅当我在URL中包含端口号时,才会加载https服务器cookie. 如何在不包含端口号的情况下加载它?

  1. The https server cookie only loads if I include the port number in the url. How do I get it to load without including the port number?

当服务器启动并加载cookie时,始终应该在客户端上加载的静态index.html不会加载,而我得到的只是写在响应对象上的内容服务器.我如何才能加载cookie,并仅加载该静态html文件? 我尝试从服务器端发送整个HTML文件作为响应.但是我不确定,再加上在浏览器中出现MIME类型问题.

When the server kicks in and loads the cookie, the static index.html that was always supposed to load on the client, doesn't load and instead all i get is what was written into the response object on the server. How do I get to load the cookie, and just load that static html file? I have tried sending in the entire html file as a respnose from the server side. But I'm not sure about that, plus i get MIME type problems in the browser.

推荐答案

我创建了一个小型演示,可能会让您走上正确的轨道: https://github.com/bergur/simple-server-with-websocket

I've created a small demo, that might get you on the right track: https://github.com/bergur/simple-server-with-websocket

此示例包括:

  1. https Web服务器
  2. websocket服务器
  3. 获取Cookie的逻辑
  4. 不提供快递服务的temp.html文件
  5. javascript类示例
  6. nodejs中依赖项注入的示例

这篇关于Https createServer,加载cookie并加载客户端index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆