javascript - Axios / Nuxt“证书已过期”仅在直接打开页面时,而不是来自另一个页面的链接
问题描述
我有一个使用 Nuxt.js 和 Axios 帮助维护的网站(但不是我自己建立的)。它目前在主页上显示奇怪的服务器行为。如果我直接访问主页(比如:)https://example.org
:
- 浏览器:服务器错误 (500)
- 服务器:证书已过期(用于 twitter 提要数据调用)
当我在example.org/about
(有效)并点击形成的链接时也会发生此错误:<a href="/" class="navbar-item logo-text">Home</a>
https://example.org
但是,如果我通过 say 上的链接访问主页(都显示链接为),该链接的example.org/about
格式如下<a href="/" class="navbar-item nuxt-link-active"><span>Home</span></a>
:
- 浏览器:页面有效!
- 服务器:没有错误
因此,奇怪的是,即使对于“/”的两个不同链接,一个会导致错误,而另一个不会(并且它们都在 URL 栏中显示相同的内容)。如果我直接打开链接,example.org:5000/tweets
那么它工作正常(脚注:不确定为什么设计选择在那里使用不同的端口,可能相关)。有没有人见过这种行为并知道为什么会发生这种情况?它在安全模式和所有主要浏览器上都存在。从工作到最近几天停止工作,代码没有发生任何变化。我收到的具体错误如下所示。
{ Error: certificate has expired
at TLSSocket.<anonymous> (_tls_wrap.js:1105:38)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket._finishInit (_tls_wrap.js:639:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:469:38)
code: 'CERT_HAS_EXPIRED',
config:
{ adapter: [Function: httpAdapter],
transformRequest: { '0': [Function: transformRequest] },
transformResponse: { '0': [Function: transformResponse] },
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers:
{ Accept: 'application/json, text/plain, */*',
'User-Agent': 'axios/0.16.2' },
baseURL: 'https://example.org:5000/',
method: 'get',
url: 'https://example.org:5000/tweets',
data: undefined },
request:
Writable {
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
domain: null,
_events:
{ response: [Function: handleResponse],
error: [Function: handleRequestError] },
_eventsCount: 2,
_maxListeners: undefined,
_options:
{ protocol: 'https:',
maxRedirects: 21,
maxBodyLength: 10485760,
hostname: 'example.org',
port: '5000',
path: '/tweets',
method: 'get',
headers: [Object],
agent: undefined,
auth: undefined,
nativeProtocols: [Object],
pathname: '/tweets' },
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function],
_currentRequest:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 6,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Object],
connection: [Object],
_header: 'GET /tweets HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nUser-Agent: axios/0.16.2\r\nHost: example.org:5000\r\nConnection: close\r\n\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Object],
socketPath: undefined,
timeout: undefined,
method: 'GET',
path: '/tweets',
_ended: false,
res: null,
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
_redirectable: [Circular],
[Symbol(outHeadersKey)]: [Object] },
_currentUrl: 'https://example.org:5000/tweets' },
response: undefined,
statusCode: 500,
name: 'NuxtServerError' }
解决方案
Upgrading to the latest version of Node resolved this issue for me. I was experiencing an identical issue to what you described on Node v8.10.0. I upgraded to Node v14.18.1 and restarted Nuxt, and now the site works normally.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
推荐阅读
- java - 开发和生产环境之间的奇怪日期错误
- c# - 天蓝色函数无法搭建 dbcontext
- c - arduino uno 快速 pwm pin5/6
- php - mysqli_stmt_close() 期望参数 1 为 mysqli_stmt,布尔值在 C:\wamp64\www\web\form11.php 第 101 行给出
- vue.js - vue js中的SSR,单击任何内容时出错
- laravel - 为什么 Dusk 不在 Homestead 环境中运行 JavaScript?
- amazon-web-services - 具有授权的 AWS Cognito 用户(如何从应用程序将用户添加到用户组?)
- google-apps-script - Google 脚本触发器因权限错误而停止工作(代码:11:28)
- sql - 具有一对多关系的 SQL 连接列
- python-3.x - 在python中将多个列表保存为csv文件