簡體   English   中英

將我的 node.js 應用程序部署到數字海洋時遇到問題

[英]Having trouble deploying my node.js app to digital ocean

我正在嘗試將我的 node.js 應用程序部署到數字海洋。 當我這樣做時,我的應用程序在本地運行良好:

node server.js

我使用 ssh 訪問從 gitlab 克隆了我的存儲庫並嘗試做同樣的事情,但所有頁面都被卡在加載階段,最終它說我的 IP 地址花了太長時間來響應。

ERR_CONNECTION_TIMED_OUT

最終我打算使用一些東西讓它永久運行,但我會為此發布一個單獨的帖子。

我通常使用我的 IP 地址:端口號來嘗試查看我的應用程序。

這是我的 server.js 文件:

const express = require('express') ,app = express(), path = require('path'), 
socket = require('socket.io'), emailModule = require('./email.js'),
formValidationModule = require('./formValidation.js'), vimeoModule = require('./vimeo.js'),
port = process.env.PORT || 3000;


let 
    server = app.listen(port,function(){
        console.log('listening to requests...');
    }), 
    io = socket(server);

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

io.on('connection', (socket)=>{
    console.log('made a connection!');

    socket.on('getShortFilmsInfo', ()=>{
        vimeoModule.videos.short_films.forEach((y)=>{
            vimeoModule.getVideoThumbnail(y).then((data)=>{
                socket.emit('shortFilmsInfo', data);
            });
        })    
    });

    socket.on('getCommercials',()=>{
        vimeoModule.videos.commercials.forEach((x)=>{
            vimeoModule.getVideoThumbnail(x).then((data)=>{
                socket.emit('commercialInfo', data);
            })
        });

    });

    socket.on('email', (data)=>{
        if(formValidationModule.checkEmptyContact(data.client, data.email, data.name, 
            data.title, data.message)){
                socket.emit('invalidData');
            }
            else {
            /**
                 * * Here you need to set your email options which includes the clients email, destination email,
                 * subject and the text (the email content).
                 */
                emailModule.setMailOptions(data.email,/*'Info@project-gorilla.co.uk'*/'salay777@hotmail.co.uk'
                , data.client + ' ' + '(' +
                data.name + ')' + ' ' + data.title, data.message).then((mailOpts)=>{
                    emailModule.send(mailOpts);
                });
                console.log('email has been sent!');
            }
    });
});

您在數字海洋中運行節點應用程序的端口被阻止從外部訪問。 配置數字海洋以將端口80443 (http 和 https 的默認端口)上的任何請求路由到您的內部 nodejs 應用程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM