GithubHelp home page GithubHelp logo

Comments (7)

allyoucanmap avatar allyoucanmap commented on August 16, 2024

Hi @t-book ,
we introduced this changes to be able to work on localhost:8081 with a remote instance of GeoNode without forcing the setup of a local GeoNode dev environment.
We improved the dev server proxy in the new webpack to be able to map all paths of the targeted remote GeoNode instance under localhost:8081.

here an example of configuration:

env.json: not committed configuration file

{
    "DEV_SERVER_HOST":  "example-geonode-host.org"
}

location of env.json

├── geonode-mapstore-client
│   ├── geonode-mapstore-client
│   │   ├── client
│   │   │   ├── env.json

after running npm start, paths of "example-geonode-host.org" are mapped under localhost:8081 using the dev bundle of MapStore client
eg:
https://example-geonode-host.org/layers/geonode:layer -> https://localhost:8081/layers/geonode:layer

The configuration described above was targeting an instance using https protocol but in your case using localhost:8000 the protocol will be http.

Could you please try to replace the webpack with this one?

const path = require('path');
const assign = require('object-assign');

const themeEntries = {
    'themes/default': path.join(__dirname, 'themes', 'default', 'theme.less'),
    'themes/preview': path.join(__dirname, 'themes', 'preview', 'theme.less')
};
const extractThemesPlugin = require('./MapStore2/build/themes.js').extractThemesPlugin;

const envJson = require('./env.json');

const DEV_SERVER_HOST = envJson.DEV_SERVER_HOST || 'ERROR:INSERT_DEV_SERVER_HOST_IN_ENV_JSON_CONFIG! eg: my-geonode-host.org';
const protocol = envJson.DEV_SERVER_HOST_PROTOCOL || 'http';

module.exports = assign({}, require('./MapStore2/build/buildConfig')(
    {
        'ms2-geonode-api': path.join(__dirname, 'js', 'api')
    },
    themeEntries,
    {
        base: __dirname,
        dist: path.join(__dirname, 'dist'),
        framework: path.join(__dirname, 'MapStore2', 'web', 'client'),
        code: [path.join(__dirname, 'js'), path.join(__dirname, 'MapStore2', 'web', 'client')]
    },
    extractThemesPlugin,
    false,
    '/static/mapstore/dist/',
    '.msgapi'
), {
    devServer: {
        https: protocol === 'https' ? true : false,
        headers: {
            'Access-Control-Allow-Origin': '*'
        },
        contentBase: [
            path.join(__dirname),
            path.join(__dirname, '..', 'static')
        ],
        before: function(app) {
            const hashRegex = /\.[a-zA-Z0-9]{1,}\.js/;
            app.use(function(req, res, next) {
                // remove hash from requests to use the local js
                if (req.url.indexOf('/static/geonode/js/ms2/utils/') !== -1
                || req.url.indexOf('/ms2-geonode-api') !== -1) {
                    req.url = req.url.replace(hashRegex, '.js');
                    req.path = req.path.replace(hashRegex, '.js');
                    req.originalUrl = req.originalUrl.replace(hashRegex, '.js');
                }
                next();
            });
        },
        proxy: [
            {
                context: [
                    '**',
                    '!**/static/mapstore/**',
                    '!**/static/geonode/js/ms2/utils/**',
                    '!**/geonode/js/ms2/utils/**',
                    '!**/MapStore2/**',
                    '!**/node_modules/**'
                ],
                target: `${protocol}://${DEV_SERVER_HOST}`,
                headers: {
                    Host: DEV_SERVER_HOST,
                    Referer: `${protocol}://${DEV_SERVER_HOST}/`
                }
            },
            {
                context: [
                    '/static/mapstore/MapStore2/web/client/translations/**',
                    '/static/geonode/js/ms2/utils/**'
                ],
                target: `${protocol}://localhost:8081`,
                secure: false,
                changeOrigin: true,
                pathRewrite: {
                    '/static/mapstore/MapStore2/web/client/translations/': '/MapStore2/web/client/translations/',
                    '/static/geonode/js/ms2/utils/': '/geonode/js/ms2/utils/'
                }
            }
        ]
    }
});

with this env.json file

{
    "DEV_SERVER_HOST": "localhost:8000"
}

The new configuration above should solve the issue with http and you should be able to work on GeoNode MapStore client on http://localhost:8081.

https://github.com/GeoNode/geonode-mapstore-client/blob/master/geonode_mapstore_client/templates/geonode-mapstore-client/base_ms.html#L23

Hence it cannot find the build anymore ?!

You are right the new correct path of the bundle is http://localhost:8081/static/mapstore/dist/ms2-geonode-api.js instead of http://localhost:8081/dist/ms2-geonode-api.js.

{%  if MAP_DEBUG %}
<script id="ms2-api" src="http://localhost:8081/static/mapstore/dist/ms2-geonode-api.js"></script>
{% else %}

please let me know if this solve the issue so I'll provide a fix,
Thanks!

from geonode-mapstore-client.

t-book avatar t-book commented on August 16, 2024

great @allyoucanmap thanks a lot for your guidance. I will give it a try and report back.

from geonode-mapstore-client.

t-book avatar t-book commented on August 16, 2024

@allyoucanmap Either I have overseen something or one piece is missing:

env.json

{
    "DEV_SERVER_HOST": "localhost:8000"
}

webpack config as shown above

templates reference:

{%  if MAP_DEBUG %}
<script id="ms2-api" src="http://localhost:8081/static/mapstore/dist/ms2-geonode-api.js"></script>
{% else %}
<script id="ms2-api" src="{% static 'mapstore/dist/ms2-geonode-api.js' %}"></script>
{% endif %}

Chunks cannot be found as port 8000 is used:
Bildschirmfoto 2020-03-30 um 12 42 00

Can you say why the build is trying to load Chunks still over 8000?

from geonode-mapstore-client.

allyoucanmap avatar allyoucanmap commented on August 16, 2024

Can you say why the build is trying to load Chunks still over 8000?

checked previous webpack and on this line was using a complete url as publicPath and force if to localhost:8081.
So the new webpack should be:

const path = require('path');
const assign = require('object-assign');

const themeEntries = {
    'themes/default': path.join(__dirname, 'themes', 'default', 'theme.less'),
    'themes/preview': path.join(__dirname, 'themes', 'preview', 'theme.less')
};
const extractThemesPlugin = require('./MapStore2/build/themes.js').extractThemesPlugin;

const envJson = require('./env.json');

const DEV_SERVER_HOST = envJson.DEV_SERVER_HOST || 'ERROR:INSERT_DEV_SERVER_HOST_IN_ENV_JSON_CONFIG! eg: my-geonode-host.org';
const protocol = envJson.DEV_SERVER_HOST_PROTOCOL || 'http';

module.exports = assign({}, require('./MapStore2/build/buildConfig')(
    {
        'ms2-geonode-api': path.join(__dirname, 'js', 'api')
    },
    themeEntries,
    {
        base: __dirname,
        dist: path.join(__dirname, 'dist'),
        framework: path.join(__dirname, 'MapStore2', 'web', 'client'),
        code: [path.join(__dirname, 'js'), path.join(__dirname, 'MapStore2', 'web', 'client')]
    },
    extractThemesPlugin,
    false,
    `${protocol}://localhost:8081/static/mapstore/dist/`,
    '.msgapi'
), {
    devServer: {
        https: protocol === 'https' ? true : false,
        headers: {
            'Access-Control-Allow-Origin': '*'
        },
        contentBase: [
            path.join(__dirname),
            path.join(__dirname, '..', 'static')
        ],
        before: function(app) {
            const hashRegex = /\.[a-zA-Z0-9]{1,}\.js/;
            app.use(function(req, res, next) {
                // remove hash from requests to use the local js
                if (req.url.indexOf('/static/geonode/js/ms2/utils/') !== -1
                || req.url.indexOf('/ms2-geonode-api') !== -1) {
                    req.url = req.url.replace(hashRegex, '.js');
                    req.path = req.path.replace(hashRegex, '.js');
                    req.originalUrl = req.originalUrl.replace(hashRegex, '.js');
                }
                next();
            });
        },
        proxy: [
            {
                context: [
                    '**',
                    '!**/static/mapstore/**',
                    '!**/static/geonode/js/ms2/utils/**',
                    '!**/geonode/js/ms2/utils/**',
                    '!**/MapStore2/**',
                    '!**/node_modules/**'
                ],
                target: `${protocol}://${DEV_SERVER_HOST}`,
                headers: {
                    Host: DEV_SERVER_HOST,
                    Referer: `${protocol}://${DEV_SERVER_HOST}/`
                }
            },
            {
                context: [
                    '/static/mapstore/MapStore2/web/client/translations/**',
                    '/static/geonode/js/ms2/utils/**'
                ],
                target: `${protocol}://localhost:8081`,
                secure: false,
                changeOrigin: true,
                pathRewrite: {
                    '/static/mapstore/MapStore2/web/client/translations/': '/MapStore2/web/client/translations/',
                    '/static/geonode/js/ms2/utils/': '/geonode/js/ms2/utils/'
                }
            }
        ]
    }
});

Question:
Are you using the application from localhost:8081 or localhost:8000?
I mean what happen if you open localhost:8081 in the browser?

thanks again

from geonode-mapstore-client.

t-book avatar t-book commented on August 16, 2024

@allyoucanmap Using your just updated webpack config solves the 404 with chunks. However something else seems to be missing as the map stays white.

This is what I see in console:

Bildschirmfoto 2020-03-30 um 13 39 54

Are you using the application from localhost:8081 or localhost:8000?
I mean what happen if you open localhost:8081 in the browser?

Django is served over 8000 using the common paver way of starting django dev server.
Mapstore is serving content from 8081 (webpack dev server)

from geonode-mapstore-client.

afabiani avatar afabiani commented on August 16, 2024

@t-book try the following ones

webpack.config.js

const path = require('path');
const assign = require('object-assign');

const themeEntries = {
    'themes/default': path.join(__dirname, 'themes', 'default', 'theme.less'),
    'themes/preview': path.join(__dirname, 'themes', 'preview', 'theme.less')
};
const extractThemesPlugin = require('./MapStore2/build/themes.js').extractThemesPlugin;

const envJson = require('./env.json');

const DEV_SERVER_HOST = envJson.DEV_SERVER_HOST || 'ERROR:INSERT_DEV_SERVER_HOST_IN_ENV_JSON_CONFIG! eg: my-geonode-host.org';
const protocol = envJson.DEV_SERVER_HOST_PROTOCOL || 'http';

module.exports = assign({}, require('./MapStore2/build/buildConfig')(
    {
        'ms2-geonode-api': path.join(__dirname, 'js', 'api')
    },
    themeEntries,
    {
        base: __dirname,
        dist: path.join(__dirname, 'dist'),
        framework: path.join(__dirname, 'MapStore2', 'web', 'client'),
        code: [path.join(__dirname, 'js'), path.join(__dirname, 'MapStore2', 'web', 'client')]
    },
    extractThemesPlugin,
    false,
    `/static/mapstore/dist/`,
    '.msgapi'
), {
    devServer: {
        https: protocol === 'https' ? true : false,
        headers: {
            'Access-Control-Allow-Origin': '*'
        },
        contentBase: [
            path.join(__dirname),
            path.join(__dirname, '..', 'static')
        ],
        before: function (app) {
            const hashRegex = /\.[a-zA-Z0-9]{1,}\.js/;
            app.use(function (req, res, next) {
                // remove hash from requests to use the local js
                if (req.url.indexOf('/static/geonode/js/ms2/utils/') !== -1
                    || req.url.indexOf('/ms2-geonode-api') !== -1) {
                    req.url = req.url.replace(hashRegex, '.js');
                    req.path = req.path.replace(hashRegex, '.js');
                    req.originalUrl = req.originalUrl.replace(hashRegex, '.js');
                }
                next();
            });
        },
        proxy: [
            {
                context: [
                    '**',
                    '!**/static/mapstore/**',
                    '!**/static/geonode/js/ms2/utils/**',
                    '!**/geonode/js/ms2/utils/**',
                    '!**/MapStore2/**',
                    '!**/node_modules/**'
                ],
                target: `${protocol}://${DEV_SERVER_HOST}`,
                headers: {
                    Host: DEV_SERVER_HOST,
                    Referer: `${protocol}://${DEV_SERVER_HOST}/`
                }
            },
            {
                context: [
                    '/static/mapstore/MapStore2/web/client/**',
                    '/static/geonode/js/ms2/utils/**'
                ],
                target: `${protocol}://localhost:8081`,
                secure: false,
                changeOrigin: true,
                pathRewrite: {
                    '/static/mapstore/MapStore2/web/client/': '/MapStore2/web/client/translations/',
                    '/static/geonode/js/ms2/utils/': '/geonode/js/ms2/utils/'
                }
            }
        ]
    }
});

env.json

{
    "DEV_SERVER_HOST": "localhost:8000"
}

Moreover, update the file geonode_mapstore_client/templates/_config.html

...
proxy: "{{ PROXY_URL }}",
...

from geonode-mapstore-client.

t-book avatar t-book commented on August 16, 2024

thanks @afabiani I will give it a try!

from geonode-mapstore-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.