小编Cod*_*F0x的帖子

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
查看次数

联系表7成功提交后如何打开弹窗

我正在使用 Wordpress 和联系表单 7。我需要使用 magnificPopup js 显示一个弹出窗口,该弹出窗口将在成功提交联系表单后出现。为 wpcf7_mail_sent 添加了一个钩子,但是我如何调用 popup 来显示使用 javascript。

例子 :

在functions.php中

add_action( 'wpcf7_mail_sent', 'after_send_mail_from_contact_form' );
function after_send_mail_from_contact_form($contact_form){
  // what to do here 
}
Run Code Online (Sandbox Code Playgroud)

在 Custom.js 文件中

$('.pay_for_course').magnificPopup({
   disableOn: 700,
   type: 'iframe',
   mainClass: 'mfp-fade',
   removalDelay: 160,
   preloader: false,
   fixedContentPos: false
});
Run Code Online (Sandbox Code Playgroud)

javascript wordpress contact-form-7 magnific-popup

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

从 Twitter API 获取更高分辨率的个人资料图像

我想从 NodeJS 中的 Twitter API 获取用户的个人资料图像。我实际上设法做到了,但它的分辨率非常低。Twitter 是一个 npm 包,“control”包含 Oauth 凭证。这是代码:

var client = new twitter(control);

app.get('/main', function(req, res){
  client.get('account/verify_credentials', function(error, params) {
  if(error) throw error;
  username = params.screen_name;
  name = params.name;
  image = params.profile_image_url;
  res.render("index.ejs", {username: username, name: name, image: image});
  });
});
Run Code Online (Sandbox Code Playgroud)

我如何更改请求,使其采用类似的形式以获得更高分辨率的图像。

javascript twitter node.js twitter-oauth

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

Node.js-无需分配即可

我编写了一个小型快递应用程序,并将路线放置在另一个文件中routes.js

module.exports = function(server) { // Server is my express object
  server.get('/something', (req, res) => {
    // Stuff
  });

  // Some other routes
}
Run Code Online (Sandbox Code Playgroud)

要在我的主文件中使用它们server.js,我require喜欢这样:

require('./routes')(server);


这工作正常,但我从未见过require没有这样的作业

const bla = require('some-module');

我在require这里使用的方式是否有效和/或良好做法?

javascript node.js express

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