Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: server.js 如何打开 HTTPS #4726

Open
Testst188 opened this issue May 18, 2024 · 2 comments
Open

[Feature Request]: server.js 如何打开 HTTPS #4726

Testst188 opened this issue May 18, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Testst188
Copy link

Problem Description

新版Docker下的js如何修改打开HTTPS

const path = require('path')

const dir = path.join(__dirname)

process.env.NODE_ENV = 'production'
process.chdir(__dirname)

const currentPort = parseInt(process.env.PORT, 10) || 3000
const hostname = process.env.HOSTNAME || '0.0.0.0'

let keepAliveTimeout = parseInt(process.env.KEEP_ALIVE_TIMEOUT, 10)
const nextConfig = {"env":{},"eslint":{"ignoreDuringBuilds":false},"typescript":{"ignoreBuildErrors":false,"tsconfigPath":"tsconfig.json"},"distDir":

process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(nextConfig)

require('next')
const { startServer } = require('next/dist/server/lib/start-server')

if (
  Number.isNaN(keepAliveTimeout) ||
  !Number.isFinite(keepAliveTimeout) ||
  keepAliveTimeout < 0
) {
  keepAliveTimeout = undefined
}

startServer({
  dir,
  isDev: false,
  config: nextConfig,
  hostname,
  port: currentPort,
  allowRetry: false,
  keepAliveTimeout,
}).catch((err) => {
  console.error(err);
  process.exit(1);
});

Solution Description

syncmeta旧版server.js的修改正常使用HTTPS

const https = require('https');
const fs = require('fs');
const options = {
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt')
};

然后修改这一行:
原来是这样:const server = http.createServer(async (req, res) => {
修改成:const server = https.createServer(options, async (req, res) => {
新版本的JS修改无效,请问如何解决

Alternatives Considered

No response

Additional Context

No response

@Testst188 Testst188 added the enhancement New feature or request label May 18, 2024
@Dean-YZG
Copy link
Contributor

我觉得,您可以保留原来的https服务,作为一个网关负责流量转发

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I think you can keep the original https service and use it as a gateway responsible for traffic forwarding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants