相关疑难解决方法(0)

342
推荐指数
7
解决办法
36万
查看次数

Heroku NodeJS http到https ssl强制重定向

我有一个应用程序启动并运行在heroku上使用https表达节点.如何识别强制重定向到heroku上的nodejs的协议?

我的应用程序只是一个简单的http服务器,它(尚未)实现heroku发送它的https请求:

/* Heroku provides the port they want you on in this environment variable (hint: it's not 80) */
app.listen(process.env.PORT || 3000);
Run Code Online (Sandbox Code Playgroud)

ssl https redirect heroku node.js

100
推荐指数
6
解决办法
4万
查看次数

每次刷新或访问页面时,Node js Express-Session 都会创建新的会话 ID

我面临的问题是:每次请求都会创建新的 sessionID。有人可以阐明这一点吗?

我正在使用的版本:

节点版本:v6.10.3 NPM 版本:3.10.10express@4.15.3express-session@1.15.3

另外,如果我没有专门设置 cookie,那么 maxAge 的默认值是多少?不确定是否需要。

您发现下面的代码有什么问题吗?请协助,因为我被困住了。

      var app = express();
        app.use(express.static(path.join(__dirname, 'landing')));
        app.use(bodyparser.json());
        app.set('trust proxy', 1) // trust first proxy
        app.use(session({
        secret: 'keyboard cat',
        resave: false,
        saveUninitialized: true,
        cookie: {secure: true}
    }))

    app.get('/', function (req, res) {
        res.sendFile(path.join(__dirname, 'landing', 'index.html'));
    });


    var contextPath = '/myportal';

    //UI url
    app.get(contextPath, function (req, res) {
        var reqValues;
              logger.info("req sessionID is :::" + req.sessionID);
           // do something
                } 
        app.use(express.static(path.join(__dirname, 'build'))); //react UI path
        res.sendFile(path.join(__dirname, 'build', 'index.html'));
  }    

    //health check …
Run Code Online (Sandbox Code Playgroud)

sessionid node.js npm express-session

7
推荐指数
1
解决办法
1万
查看次数

Node.js + Express.js | 尝试设置 HTTPS 服务器

我正在尝试使用 Node.js 和 Express.js 设置 HTTPS 服务器。

我目前正在尝试:

const filesystem = require('fs');
const express = require('express');
const server = express();
const http = require('http').Server(server);
const https = require('https');
const io = require('socket.io')(http);
require('./routes')(server);
require('./chat-logic')(io);

// Dummy cert
const privateKey  = filesystem.readFileSync('cert/key.pem', 'utf8');
const certificate = filesystem.readFileSync('cert/cert.pem', 'utf8');

const credentials = {key: privateKey, cert: certificate};
const httpsServer = https.createServer(credentials, server);

server.use(express.static(__dirname + '/src'));
http.listen(3000, () => console.log('Listening on *3000'));
httpsServer.listen(3443, () => console.log('HTTPS on *3443'));
Run Code Online (Sandbox Code Playgroud)

但是,我收到此错误:

_tls_common.js:134
      c.context.setKey(key, passphrase);
                ^

Error: …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express

6
推荐指数
1
解决办法
3311
查看次数

如何运行 Angular 通用 HTTPS

我在主页上遵循 angular 通用:https : //angular.io/guide/universal

没有通用,我用命令运行我的 angular 项目

ng serve --ssl true --ssl-key /node_modules/browser-sync/lib/server/certs/server.key --ssl-cert /node_modules/browser-sync/lib/server/certs/server.crt --主机 0.0.0.0

现在,我将通用添加到我的项目中,但不知道如何设置它使用“https”运行。
请帮帮我。

这是我的 server.ts

导入 'zone.js/dist/zone-node'; 从“@angular/core”导入{enableProdMode};
// Express Engine
import {ngExpressEngine} from '@nguniversal/express-engine';
// 为延迟加载导入模块映射 import {provideModuleMap} from '@nguniversal/module-map-ngfactory-loader';

import * as express from 'express';
从“路径”导入 {join};

// 在 Prod 模式下更快的服务器渲染(从不需要开发模式)
enableProdMode();

// Express 服务器
const app = express();

const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist/browser');

// * 笔记 ::
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main');

// …

angular-universal angular angular7

6
推荐指数
1
解决办法
2140
查看次数

让我们以“错误:EACCES:权限被拒绝,打开'/etc/letsencrypt/live/domain.net/privkey.pem'”开头的SSL进行加密

我尝试通过Node.js使用SSL,但由于,它无法正常工作permission denied

try {
var TLSoptions = {
    key: fs.readFileSync("/etc/letsencrypt/live/domain.work/privkey.pem"),
    cert: fs.readFileSync("/etc/letsencrypt/live/domain.work/cert.pem")
};

https.createServer(TLSoptions, app).listen(port, host, function() {
   console.log("TLS Website started.")
}); catch(e) {
    console.log(e)
}
Run Code Online (Sandbox Code Playgroud)

=>

{ Error: EACCES: permission denied, open '/etc/letsencrypt/live/domain.work/privkey.pem'
at Object.fs.openSync (fs.js:663:18)
... (Librarys dump)
errno: -13,
code: 'EACCES',
syscall: 'open',
path: '/etc/letsencrypt/live/domain.work/privkey.pem' }
Run Code Online (Sandbox Code Playgroud)

因此,我尝试重新制作* .pem文件。

rm -f /etc/letsencrypt/live
rm -f /etc/letsencrypt/archive    
rm -f /etc/letsencrypt/renewal
sudo ./letsencrypt-auto certonly -a standalone -d domain.work
Run Code Online (Sandbox Code Playgroud)

并检查文件权限。

/etc/letsencrypt/live/domain.work$ ls -lsa
total 12
4 drwxr-xr-x 2 root root …
Run Code Online (Sandbox Code Playgroud)

ssl node.js lets-encrypt

4
推荐指数
2
解决办法
3708
查看次数

如何在 Node.js 中使用 HTTPS

我对 HTTPS、SSL 等几乎没有经验。

我想知道如何通过 HTTPS 使用 Node.js。我知道如何很好地使用 node.js,但是在使用 HTTPS 时它会出错。

我想我需要安装一些东西(openSSL?)。我想知道我必须在 Windows 8.1 计算机上安装的所有东西(不,我不想获得任何形式的 linux。也没有 cygwin),以便使用 node.js HTTPS 服务器。

我不需要有付费证书,我只需要让它工作。它没有接收来自浏览器的请求,所以我不关心付费证书。

ssl https openssl http node.js

3
推荐指数
1
解决办法
6401
查看次数