node.js - Nodejs Elastic benastalk拒绝连接到上游/上游过早关闭
问题描述
在弹性 beantalk 中运行我的应用程序时出现以下错误:这很奇怪,因为如果我独立点击这些路由[error] 3636#0: *295 upstream prematurely closed connection while reading response header from upstream
, [error] 3636#0: *295 connect() failed (111: Connection refused) while connecting to upstream
它工作正常。从我的 vuex 操作触发这些路由时,它只会出现错误。
以下是访问我的 FFmpeg 路由时的网络选项卡:
以下是从 vuex 触发的生成视频操作。
async [GENERATE_VIDEO]({state, rootState, dispatch, commit}){
const username = rootState.user.currentUser.username;
const s3Id = rootState.templates.currentVideo.stock_s3_id;
const type = rootState.dataClay.fileFormat || state.type;
const vid = new Whammy.fromImageArray(state.captures, 30);
vid.lastModifiedDate = new Date();
vid.name = "canvasVideo.webm";
const data = new FormData();
const id = `${username}_${new Date().getTime()}`;
data.append("id", id);
data.append("upload", vid);
const projectId = await dispatch(INSERT_PROJECT);
await dispatch(UPLOAD_TEMP_FILE, data);
const key = await dispatch(CONVERT_FILE_TYPE, { id, username, type, projectId});
const role = rootState.user.currentUser.role;
state.file = `/api/files/${key}`;
let message;
if(role!='banner'){
message =`<p>Your video is ready.</p> <a href="${state.file}" download class="btn btn-primary btn-block">Download</a>`;
} else {
message = `<p>Your video is ready. You may download your file from your banner account</p>`;
const resolution = rootState.dataClay.matrix[0];
await dispatch(EXPORT_TO_BANNER, { s3Id, fileUrl: key, extension: `.${type}`, resolution});
}
这是在操作中调用的 api 路由。
async [UPLOAD_TEMP_FILE]({ commit }, data) {
try {
const response = await axios.post("/api/canvas-editor/upload-temp", data);
return response.data;
} catch (error) {
console.log(error);
}
},
async [CONVERT_FILE_TYPE]({commit}, data) {
try{
const response = await axios.post("/api/canvas-editor/ffmpeg", data);
return response.data;
} catch(error){
console.log(error);
}
}
}
正如我所说,我的所有路由都正常工作,并且应用程序在 localhost 上按预期运行,但是当上传到 aws 时,我收到了意外错误。
解决方案
经过一番挖掘,我发现我没有设置ffmpeg路径。完成此操作后,效果很好。
const ffmpeg = require('fluent-ffmpeg');
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
ffmpeg.setFfmpegPath(ffmpegPath);
module.exports = ffmpeg;