Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config: Override backend locations on localhost #12

Open
wants to merge 1 commit into
base: config/master
Choose a base branch
from

Conversation

janiemi
Copy link

@janiemi janiemi commented Jan 10, 2025

Override backend locations (settings.korpBackendURL, settings.downloadCgiScript) to point to localhost locations when the frontend is running on localhost. This makes it possible to use the configuration file without modifications both in production and when testing locally.

A problem with this solution is that the exact localhost backend locations are those used by me (@janiemi): someone else might use different locations. However, I don’t know if someone else currently runs Korp locally, and this was the easiest solution I came up with to make it possible to use the configuration file also locally without modifications.

@janiemi
Copy link
Author

janiemi commented Jan 10, 2025

@Traubert, @mmatthiesencsc, @aajarven: What do you think: is it ok to specify localhost backend locations in the frontend configuration like this, in particular as they are specific to my own local Korp installation?

@Traubert
Copy link

Personally I'd control this in the deployment process, rather than code, with eg. Jinja2 templates in Ansible. We could make an example of this / point you to something in Kielipankki-korp-ansible?

@janiemi
Copy link
Author

janiemi commented Jan 10, 2025

@Traubert, I suppose that would in general be a better solution, although I don’t know exactly how it would be implemented in this case.

I mostly run Korp locally via webpack-dev-server (yarn dev), which automatically reloads on the browser when the code is changed, and I’d like to keep it working without extra steps. I also don’t know if you can call that a deployment process.

I’d like to be able to use the same code as in production without having to make temporary changes with a risk of accidentally committing to the production code. Maybe we could have for the locations a separate file that wouldn’t be version-controlled, but how would the information in it be read to or otherwise incorporated into config.js?

In any case, I wouldn’t like to make any significant modifications to this Korp version to support this kind of configuration, as it’ll have to be changed in the next version anyway.

@mmatthiesencsc
Copy link
Collaborator

Jyrki, I suggest to indeed have locations in a separate file and the production code checks for that file and reads the contents if present. That way I think we get the best of both worlds and are very flexible.

@janiemi
Copy link
Author

janiemi commented Jan 10, 2025

@mmatthiesencsc, I agree in principle. However, it’s not obvious to me how you would do that in JavaScript, and I wouldn’t like to spend much time in trying to figure that out, so I’d be grateful for an example.

Maybe I’ll try to make do with modifying config.js for local use (and try to avoid committing that change or commit locally only) until we upgrade to a more recent Korp version.

@mmatthiesencsc
Copy link
Collaborator

yarn seems to have distinction between dev and prod:

$ cat webpack.dev.js 
const {merge} = require('webpack-merge');
const common = require('./webpack.common.js');


module.exports = merge(common, {
  devServer: {
    host: process.env.KORP_HOST || "localhost",
    port: process.env.KORP_PORT || 9111
  },
  devtool: 'inline-source-map',
  mode: 'development'
});

maybe add webpack.common-dev.js? My yarn knowledge is limited, so ymmv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants