无法将Cesium JS应用程序部署到AWS Elastic Beanstalk

时间:2018-03-23 19:17:52

标签: amazon-elastic-beanstalk cesium

我有一个应用程序,我想部署到AWS Elastic Beanstalk,但是已经收到了大量错误。我的问题是我不知道要捆绑哪些文件。我正在使用其中一个Cesium示例和我自己的参数。 .html通过localhost和node.js在Web浏览器中打开。但是,当我尝试将我认为正确的文件捆绑在一起时,我在日志中遇到了部署错误。我想点击3D Tiles Feature Styling。 html在下面的文件夹结构中。我已经确保express在node_modules中并且在编译文件时尝试了不同的场景。这个问题的解决方案是什么?我还根据其他线程建议将app.js更改为main.js。

.zip structure used to deploy

HTML:

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">  <!-- Use Chrome Frame in IE -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <meta name="description" content="Interactive 3D Tiles styling.">
    <meta name="cesium-sandcastle-labels" content="Showcases, 3D Tiles">
    <title>Cesium Demo</title>
    <script type="text/javascript" src="/Sandcastle-header.js"></script>
    <script type="text/javascript" src="/require.js"></script>
    <script type="text/javascript" src="/apps.js"></script> b 
    <script type="text/javascript">
    require.config({
        baseUrl : '../../../Source',
        waitSeconds : 60
    });
    </script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
    @import url(/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
    'use strict';
//Sandcastle_Begin
// A demo of interactive 3D Tiles styling
// Styling language Documentation: https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/Styling
// Building data courtesy of NYC OpenData portal: http://www1.nyc.gov/site/doitt/initiatives/3d-building.page
Cesium.Ion.defaultAccessToken = 'mykey';
var viewer = new Cesium.Viewer('cesiumContainer');

// Set the initial camera view to look at Manhattan
var initialPosition = Cesium.Cartesian3.fromDegrees(-118.4912, 34.0195, 753);
var initialOrientation = new Cesium.HeadingPitchRoll.fromDegrees(21.27879878293835, -21.34390550872461, 0.0716951918898415);
viewer.scene.camera.setView({
    destination: initialPosition,
    orientation: initialOrientation,
    endTransform: Cesium.Matrix4.IDENTITY
});

// Load the NYC buildings tileset.
var tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(3099) });
viewer.scene.primitives.add(tileset);

// Color buildings based on their height.
function colorByHeight() {
    tileset.style = new Cesium.Cesium3DTileStyle({
        color: {
            conditions: [
                ["${height} >= 300", "rgba(45, 0, 75, 0.5)"],
                ["${height} >= 200", "rgb(102, 71, 151)"],
                ["${height} >= 100", "rgb(170, 162, 204)"],
                ["${height} >= 50", "rgb(224, 226, 238)"],
                ["${height} >= 25", "rgb(252, 230, 200)"],
                ["${height} >= 10", "rgb(248, 176, 87)"],
                ["${height} >= 5", "rgb(198, 106, 11)"],
                ["true", "rgb(127, 59, 8)"]
            ]
        }
    });
}

// Color buildings by their total area.
function colorByArea() {
    tileset.style = new Cesium.Cesium3DTileStyle({
        color: "mix(color('yellow'), color('red'), min(${area} / 10000.0, 1.0))"
    });
}

// Color buildings by their latitude coordinate.
function colorByLatitude() {
    tileset.style = new Cesium.Cesium3DTileStyle({
        color: {
            conditions: [
                ["${latitude} >= 0.7125", "color('purple')"],
                ["${latitude} >= 0.712", "color('red')"],
                ["${latitude} >= 0.7115", "color('orange')"],
                ["${latitude} >= 0.711", "color('yellow')"],
                ["${latitude} >= 0.7105", "color('lime')"],
                ["${latitude} >= 0.710", "color('cyan')"],
                ["true", "color('blue')"]
            ]
        }
    });
}

// Color buildings by distance from a landmark.
function colorByDistance() {
    tileset.style = new Cesium.Cesium3DTileStyle({
        defines : {
            distance : "distance(vec2(${longitude}, ${latitude}), vec2(-1.291777521, 0.7105706624))"
        },
        color : {
            conditions : [
                ["${distance} > 0.0002", "color('gray')"],
                ["true", "mix(color('yellow'), color('green'), ${distance} / 0.0002)"]
            ]
        }
    });
}

// Color buildings with a '3' in their name.
function colorByNameRegex() {
    tileset.style = new Cesium.Cesium3DTileStyle({
        color : "(regExp('3').test(${name})) ? color('cyan', 0.9) : color('purple', 0.1)"
    });
}

// Show only buildings greater than 200 meters in height.
function hideByHeight() {
    tileset.style = new Cesium.Cesium3DTileStyle({
        show : "${height} > 200"
    });
}

Sandcastle.addToolbarMenu([{
    text : 'Color By Height',
    onselect : function() {
        colorByHeight();
    }
}, {
    text : 'Color By Area',
    onselect : function() {
        colorByArea();
    }
}, {
    text : 'Color By Latitude',
    onselect : function() {
        colorByLatitude();
    }
}, {
    text : 'Color By Distance',
    onselect : function() {
        colorByDistance();
    }
}, {
    text : 'Color By Name Regex',
    onselect : function() {
        colorByNameRegex();
    }
}, {
    text : 'Hide By Height',
    onselect : function() {
        hideByHeight();
    }
}]);

colorByHeight();

//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
    startup(Cesium);
} else if (typeof require === "function") {
    require(["Cesium"], startup);
}
</script>
</body>
</html>

.app js

    /*eslint-env node*/
'use strict';
(function() {
    var express = require('express');
    var compression = require('compression');
    var fs = require('fs');
    var url = require('url');
    var request = require('request');

    var gzipHeader = Buffer.from('1F8B08', 'hex');

    var yargs = require('yargs').options({
        'port' : {
            'default' : 3000,
            'description' : 'Port to listen on.'
        },
        'public' : {
            'type' : 'boolean',
            'description' : 'Run a public server that listens on all interfaces.'
        },
        'upstream-proxy' : {
            'description' : 'A standard proxy server that will be used to retrieve data.  Specify a URL including port, e.g. "http://proxy:8000".'
        },
        'bypass-upstream-proxy-hosts' : {
            'description' : 'A comma separated list of hosts that will bypass the specified upstream_proxy, e.g. "lanhost1,lanhost2"'
        },
        'help' : {
            'alias' : 'h',
            'type' : 'boolean',
            'description' : 'Show this help.'
        }
    });
    var argv = yargs.argv;

    if (argv.help) {
        return yargs.showHelp();
    }

    // eventually this mime type configuration will need to change
    // https://github.com/visionmedia/send/commit/d2cb54658ce65948b0ed6e5fb5de69d022bef941
    // *NOTE* Any changes you make here must be mirrored in web.config.
    var mime = express.static.mime;
    mime.define({
        'application/json' : ['czml', 'json', 'geojson', 'topojson'],
        'image/crn' : ['crn'],
        'image/ktx' : ['ktx'],
        'model/gltf+json' : ['gltf'],
        'model/gltf-binary' : ['bgltf', 'glb'],
        'application/octet-stream' : ['b3dm', 'pnts', 'i3dm', 'cmpt', 'geom', 'vctr'],
        'text/plain' : ['glsl']
    }, true);

    var app = express();
    app.use(compression());
    app.use(function(req, res, next) {
        res.header('Access-Control-Allow-Origin', '*');
        res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
        next();
    });

    function checkGzipAndNext(req, res, next) {
        var reqUrl = url.parse(req.url, true);
        var filePath = reqUrl.pathname.substring(1);

        var readStream = fs.createReadStream(filePath, { start: 0, end: 2 });
        readStream.on('error', function(err) {
            next();
        });

        readStream.on('data', function(chunk) {
            if (chunk.equals(gzipHeader)) {
                res.header('Content-Encoding', 'gzip');
            }
            next();
        });
    }

    var knownTilesetFormats = [/\.b3dm/, /\.pnts/, /\.i3dm/, /\.cmpt/, /\.glb/, /\.geom/, /\.vctr/, /tileset.*\.json$/];
    app.get(knownTilesetFormats, checkGzipAndNext);

    app.use(express.static(__dirname));

    function getRemoteUrlFromParam(req) {
        var remoteUrl = req.params[0];
        if (remoteUrl) {
            // add http:// to the URL if no protocol is present
            if (!/^https?:\/\//.test(remoteUrl)) {
                remoteUrl = 'http://' + remoteUrl;
            }
            remoteUrl = url.parse(remoteUrl);
            // copy query string
            remoteUrl.search = url.parse(req.url).search;
        }
        return remoteUrl;
    }

    var dontProxyHeaderRegex = /^(?:Host|Proxy-Connection|Connection|Keep-Alive|Transfer-Encoding|TE|Trailer|Proxy-Authorization|Proxy-Authenticate|Upgrade)$/i;

    function filterHeaders(req, headers) {
        var result = {};
        // filter out headers that are listed in the regex above
        Object.keys(headers).forEach(function(name) {
            if (!dontProxyHeaderRegex.test(name)) {
                result[name] = headers[name];
            }
        });
        return result;
    }

    var upstreamProxy = argv['upstream-proxy'];
    var bypassUpstreamProxyHosts = {};
    if (argv['bypass-upstream-proxy-hosts']) {
        argv['bypass-upstream-proxy-hosts'].split(',').forEach(function(host) {
            bypassUpstreamProxyHosts[host.toLowerCase()] = true;
        });
    }

    app.get('/proxy/*', function(req, res, next) {
        // look for request like http://localhost:8080/proxy/http://example.com/file?query=1
        var remoteUrl = getRemoteUrlFromParam(req);
        if (!remoteUrl) {
            // look for request like http://localhost:8080/proxy/?http%3A%2F%2Fexample.com%2Ffile%3Fquery%3D1
            remoteUrl = Object.keys(req.query)[0];
            if (remoteUrl) {
                remoteUrl = url.parse(remoteUrl);
            }
        }

        if (!remoteUrl) {
            return res.status(400).send('No url specified.');
        }

        if (!remoteUrl.protocol) {
            remoteUrl.protocol = 'http:';
        }

        var proxy;
        if (upstreamProxy && !(remoteUrl.host in bypassUpstreamProxyHosts)) {
            proxy = upstreamProxy;
        }

        // encoding : null means "body" passed to the callback will be raw bytes

        request.get({
            url : url.format(remoteUrl),
            headers : filterHeaders(req, req.headers),
            encoding : null,
            proxy : proxy
        }, function(error, response, body) {
            var code = 500;

            if (response) {
                code = response.statusCode;
                res.header(filterHeaders(req, response.headers));
            }

            res.status(code).send(body);
        });
    });

    var server = app.listen(argv.port, argv.public ? undefined : 'localhost', function() {
        if (argv.public) {
            console.log('Cesium development server running publicly.  Connect to http://localhost:%d/', server.address().port);
        } else {
            console.log('Cesium development server running locally.  Connect to http://localhost:%d/', server.address().port);
        }
    });

    server.on('error', function (e) {
        if (e.code === 'EADDRINUSE') {
            console.log('Error: Port %d is already in use, select a different port.', argv.port);
            console.log('Example: node server.js --port %d', argv.port + 1);
        } else if (e.code === 'EACCES') {
            console.log('Error: This process does not have permission to listen on port %d.', argv.port);
            if (argv.port < 1024) {
                console.log('Try a port number higher than 1024.');
            }
        }
        console.log(e);
        process.exit(1);
    });

    server.on('close', function() {
        console.log('Cesium development server stopped.');
    });

    var isFirstSig = true;
    process.on('SIGINT', function() {
        if (isFirstSig) {
            console.log('Cesium development server shutting down.');
            server.close(function() {
              process.exit(0);
            });
            isFirstSig = false;
        } else {
            console.log('Cesium development server force kill.');
            process.exit(1);
        }
    });

})();

日志:

-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cesium
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls cesium
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/app/current/npm-debug.log

> cesium@1.43.0 start /var/app/current
> node server.js

module.js:471
    throw err;
    ^

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at /var/app/current/server.js:4:19
    at Object.<anonymous> (/var/app/current/server.js:201:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

npm ERR! Linux 4.9.77-31.58.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/npm" "start"
npm ERR! node v6.11.5
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! cesium@1.43.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cesium@1.43.0 start script 'node server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the cesium package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cesium
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls cesium
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/app/current/npm-debug.log

> cesium@1.43.0 start /var/app/current
> node server.js

module.js:471
    throw err;
    ^

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at /var/app/current/server.js:4:19
    at Object.<anonymous> (/var/app/current/server.js:201:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

npm ERR! Linux 4.9.77-31.58.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/npm" "start"
npm ERR! node v6.11.5
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! cesium@1.43.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cesium@1.43.0 start script 'node server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the cesium package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cesium
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls cesium
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/app/current/npm-debug.log

> Elastic-Beanstalk-Sample-App@0.0.1 start /var/app/current
> node app.js

Server running at http://127.0.0.1:8081/

0 个答案:

没有答案