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

Add server init logic for SAML and DNS #283

Merged
merged 3 commits into from
Mar 5, 2023

Conversation

humphd
Copy link
Contributor

@humphd humphd commented Feb 28, 2023

Fixes #275.

We have a number of modules that require some kind of asynchronous setup step before the app can start. Currently, this includes:

  • SAML: we need to download the IdP's metadata XML and use it to create an IdentityProvider instance
  • DNS: in development, we need to create a hosted zone on the mock Rout53 server

In order to facility this kind of logic, I'm adding a step before the server is started that does any init() that a module might need done. All you have to do is export an async function, and we'll call it at startup.

The way that Remix hot-reloads work, I had to do a bit of gymnastics to preserve module state after a server-side reload. The current db.server.ts file shows a pattern to use: define a global variable and stick the instance data there, then restore it when the module is reloaded.

I've also moved the SAML code into app/lib/ like the other server modules.

To test this, do npm run build and npm run dev and you'll see something like this:

info: 🔌 setting up prisma client to localhost:3306
info: app initializing...
debug: SAML init: downloading IdP metadata from http://localhost:8081/simplesaml/saml2/idp/metadata.php
debug: DNS init: created hosted zone EPE35EFYJZJFNT8 for starchart.invalid
Watching Remix app in development mode...
💿 Built in 311ms
info: ✅ app ready: http://localhost:8080

Now the metadata is downloaded (SAML login should work) and a DNS hosted zone has been created (the DNS stuff in #274 should work in development).

@humphd humphd added the category: back end Back end part of our web service label Feb 28, 2023
@humphd humphd added this to the Milestone 0.5 milestone Feb 28, 2023
@humphd humphd self-assigned this Feb 28, 2023
@humphd humphd mentioned this pull request Feb 28, 2023
app/lib/saml.server.ts Show resolved Hide resolved
@humphd humphd requested a review from Genne23v March 3, 2023 15:44
@humphd humphd merged commit 9fdd304 into DevelopingSpace:main Mar 5, 2023
Genne23v pushed a commit to Genne23v/starchart that referenced this pull request Mar 7, 2023
* Move saml.server.ts into app/lib

* Add server startup hook for server modules needing an init step

* Add service container for DNS in e2e tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: back end Back end part of our web service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add npm script to create Route53 hosted zone for local dev
3 participants