简体   繁体   English

从远程计算机访问JHipster应用程序(在开发模式下运行)

[英]Accessing a JHipster application (running in dev mode) from a remote machine

I have a JHipster Application running in the dev mode. 我有一个在开发人员模式下运行的JHipster应用程序。 It is using spring boot in the back-end and Angular 6 in the front end. 它在后端使用弹簧靴,在前端使用Angular 6。

To run the application on my local machine, I am using "npm start" or "yarn start" to start the client side server and to start the back-end server, I am running the springboot application from the Eclipse IDE. 为了在本地计算机上运行该应用程序,我正在使用“ npm start”或“ yarn start”启动客户端服务器并启动后端服务器,我正在从Eclipse IDE运行springboot应用程序。 This setup works fine on my local machine. 此设置在我的本地计算机上运行良好。

But what changes should I make in the application to access it from a remote machine? 但是,我应该对应用程序进行哪些更改以从远程计算机访问它? I tried modifying parent-dir\\webpack\\webpack.dev.js to make it happen but it didn't work. 我尝试修改parent-dir \\ webpack \\ webpack.dev.js使其实现,但是没有用。 I had read somewhere that remote access is possible by running "ng serve" but as far as I know, JHipster does not support this command. 我读过某个地方可以通过运行“ ng serve”来进行远程访问,但是据我所知,JHipster不支持此命令。

Below is the webpack.dev.js file 以下是webpack.dev.js文件

const webpack = require('webpack');
const writeFilePlugin = require('write-file-webpack-plugin');
const webpackMerge = require('webpack-merge');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
const path = require('path');
const sass = require('sass');

const utils = require('./utils.js');
const commonConfig = require('./webpack.common.js');

const ENV = 'development';

module.exports = (options) => webpackMerge(commonConfig({ env: ENV }), {
    devtool: 'eval-source-map',
    devServer: {
        contentBase: './target/www',
        proxy: [{
            context: [
                /* jhipster-needle-add-entity-to-webpack - JHipster will add entity api paths here */
                '/api',
                '/management',
                '/swagger-resources',
                '/v2/api-docs',
                '/h2-console',
                '/auth'
            ],
            target: `http${options.tls ? 's' : ''}://127.0.0.1:8080`,
            secure: false,
            changeOrigin: options.tls,
            headers: { host: 'localhost:9000' }
        }],
        stats: options.stats,
        watchOptions: {
            ignored: /node_modules/
        }
    },
    entry: {
        polyfills: './src/main/webapp/app/polyfills',
        global: './src/main/webapp/content/scss/global.scss',
        main: './src/main/webapp/app/app.main'
    },
    output: {
        path: utils.root('target/www'),
        filename: 'app/[name].bundle.js',
        chunkFilename: 'app/[id].chunk.js'
    },
    module: {
        rules: [{
            test: /\.ts$/,
            enforce: 'pre',
            loader: 'tslint-loader',
            exclude: ['node_modules', new RegExp('reflect-metadata\\' + path.sep + 'Reflect\\.ts')]
        },
        {
            test: /\.ts$/,
            use: [
                'angular2-template-loader',
                {
                    loader: 'cache-loader',
                    options: {
                      cacheDirectory: path.resolve('target/cache-loader')
                    }
                },
                {
                    loader: 'thread-loader',
                    options: {
                        // there should be 1 cpu for the fork-ts-checker-webpack-plugin
                        workers: require('os').cpus().length - 1
                    }
                },
                {
                    loader: 'ts-loader',
                    options: {
                        transpileOnly: true,
                        happyPackMode: true
                    }
                },
                'angular-router-loader'
            ],
            exclude: ['node_modules']
        },
        {
            test: /\.scss$/,
            use: ['to-string-loader', 'css-loader', {
                loader: 'sass-loader',
                options: { implementation: sass }
            }],
            exclude: /(vendor\.scss|global\.scss)/
        },
        {
            test: /(vendor\.scss|global\.scss)/,
            use: ['style-loader', 'css-loader', 'postcss-loader', {
                loader: 'sass-loader',
                options: { implementation: sass }
            }]
        },
        {
            test: /\.css$/,
            use: ['to-string-loader', 'css-loader'],
            exclude: /(vendor\.css|global\.css)/
        },
        {
            test: /(vendor\.css|global\.css)/,
            use: ['style-loader', 'css-loader']
        }]
    },
    stats: process.env.JHI_DISABLE_WEBPACK_LOGS ? 'none' : options.stats,
    plugins: [
        process.env.JHI_DISABLE_WEBPACK_LOGS
            ? null
            : new SimpleProgressWebpackPlugin({
                format: options.stats === 'minimal' ? 'compact' : 'expanded'
              }),
        new FriendlyErrorsWebpackPlugin(),
        new ForkTsCheckerWebpackPlugin(),
        new BrowserSyncPlugin({
            host: 'localhost',
            port: 9000,
            proxy: {
                target: 'http://localhost:9060'
            },
            socket: {
                clients: {
                    heartbeatTimeout: 60000
                }
            }
        }, {
            reload: false
        }),
        new webpack.ContextReplacementPlugin(
            /angular(\\|\/)core(\\|\/)/,
            path.resolve(__dirname, './src/main/webapp')
        ),
        new writeFilePlugin(),
        new webpack.WatchIgnorePlugin([
            utils.root('src/test'),
        ]),
        new WebpackNotifierPlugin({
            title: 'JHipster',
            contentImage: path.join(__dirname, 'logo-jhipster.png')
        })
    ].filter(Boolean),
    mode: 'development'
});

Thanks in advance. 提前致谢。

By default, webpack dev server listens on 127.0.0.1, you must configure it to listen on 0.0.0.0. 默认情况下,webpack开发服务器侦听127.0.0.1,您必须将其配置为侦听0.0.0.0。

Edit webpack/webpack.dev.js and set host to 0.0.0.0: 编辑webpack/webpack.dev.js并将host设置为0.0.0.0:

devServer: {
    host: '0.0.0.0',

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JHipster应用程序在开发模式下生成消息“ this.driver.matchesElement” - JHipster Application produces message “this.driver.matchesElement” in dev mode Jhipster:应用程序正在运行,但浏览器上没有输出 - Jhipster: application is running but no output on the browser 如何在开发模式下为 Angular 应用程序提供服务? - How to serve Angular application in dev mode? 在访问 Marketo REST API 时在 Heroku 上部署 jhipster Angular 应用程序后出现内容安全策略错误 - getting Content Security Policy error after deploying jhipster Angular application on Heroku while accessing Marketo REST APIs 在Angular / JHipster应用程序中使用另一个模块的组件 - Using Components from Another Module on a Angular/JHipster Application 在Jhipster中访问文件(Angular + Springboot) - Accessing files in Jhipster (Angular + Springboot) JHIPSTER 应用程序升级 - JHIPSTER Application UPGRADE Jhipster应用程序生成失败 - Jhipster application generation is failing CORS 关于在 Azure 虚拟机之外的浏览器上访问 Web 应用程序的问题 - CORS ISSUES on Accessing Web Application on a Browser Outside Azure Virtual Machine 无法在 IE11 上运行 jhipster (6.3.1) 生成的应用程序 - Can't get jhipster (6.3.1) generated application running on IE11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM