Skip to content

Commit

Permalink
Add support for devserver --back-end option.
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-lee committed Apr 20, 2024
1 parent d846b4f commit 5aeb9fc
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 23 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@ $ cd cspace-ui-plugin-profile-publicart.js
$ npm install
```

To run the cspace-ui application configured with this plugin:
To run the cspace-ui application configured with this plugin in development, using a remote
back-end CollectionSpace server:

```
$ npm run devserver
$ npm run devserver --back-end=https://publicart.dev.collectionspace.org
```

Then open a browser to http://localhost:8080.

By default, the application served from the dev server will use the CollectionSpace services API
located at http://localhost:8180.

To run the application against CollectionSpace services located on a different host, edit
index.html, and change the `serverUrl` configuration property. For example, to use a server running
on nightly.collectionspace.org, port 8180, use the settings:
Alternatively, to run the cspace-ui application configured with this plugin in development, using
the UI configuration in index.html:

```
cspaceUI({
serverUrl: 'http://nightly.collectionspace.org:8180',
// ...
});
$ npm run devserver
```

By default, the configuration in index.html uses the CollectionSpace services API located at
http://localhost:8180. To run the application against CollectionSpace services located on a
different host, edit index.html, and change the `serverUrl` configuration property. Note that the
specified server must be configured to allow CORS requests from http://localhost:8080.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
This bundle is served from the URL /cspaceUIPluginProfilePublicArt.js, but it does not exist in
the filesystem.
-->
<script src="/cspaceUIPluginProfilePublicArt.js"></script>
<script src="/webpack-dev-assets/cspaceUIPluginProfilePublicArt.js"></script>
</head>
<body>
<div id="cspace"></div>
Expand Down
27 changes: 17 additions & 10 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
const { execSync } = require('child_process');
const path = require('path');
const webpack = require('webpack');
const webpackDevServerConfig = require('./webpackDevServerConfig');

/**
* The public path to local webpack assets. This is chosen to have low chance of collision with any
* path on a proxied back-end (e.g., "/cspace/core" or "/cspace-services"). This should start and
* end with slashes.
*/
const publicPath = '/webpack-dev-assets/';

const library = 'cspaceUIPluginProfilePublicArt';
const isProduction = process.env.NODE_ENV === 'production';
Expand All @@ -24,7 +32,7 @@ try {
console.log('Failed to get repository url from npm: %s', err.stderr.toString());
}

const config = {
module.exports = async () => ({
mode: isProduction ? 'production' : 'development',
entry: './src/index.js',
output: {
Expand All @@ -33,6 +41,7 @@ const config = {
libraryTarget: 'umd',
libraryExport: 'default',
path: path.resolve(__dirname, 'dist'),
publicPath,
},
module: {
rules: [
Expand Down Expand Up @@ -87,12 +96,10 @@ const config = {
resolve: {
extensions: ['.js', '.jsx'],
},
devServer: {
historyApiFallback: true,
static: {
directory: __dirname,
},
},
};

module.exports = config;
devServer: await webpackDevServerConfig({
library,
localIndex: process.env.npm_config_local_index,
proxyTarget: process.env.npm_config_back_end,
publicPath,
}),
});
Loading

0 comments on commit 5aeb9fc

Please sign in to comment.