Skip to content

Commit

Permalink
Made the URL rewrite mechanism a little more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
hugithordarson committed Jul 13, 2023
1 parent 350b0a7 commit bcb0a4c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions ng-appserver/src/main/java/ng/appserver/NGApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public class NGApplication {
*/
private NGResourceManager _resourceManager;

/**
* A list of patterns that will be applied to URLs before they are processed by the framework
*/
private List<Pattern> urlRewritePatterns;

/**
* In the old WO world, this would have been called "requestHandlers".
* Since we want to have more dynamic route resolution, it makes sense to move that to a separate object.
Expand Down Expand Up @@ -102,6 +107,9 @@ public static <E extends NGApplication> E runAndReturn( final String[] args, fin
// FIXME: This is just plain wrong. We want properties to be accessible during application initialization. Here we're loading properties after construction
application._properties = properties;

application.urlRewritePatterns = new ArrayList<>();
application.urlRewritePatterns.add( Pattern.compile( "^/(cgi-bin|Apps)/WebObjects/" + properties.propWOApplicationName() + ".woa(/[0-9])?" ) );

// FIXME: We also might want to be more explicit about this
application.start();

Expand Down Expand Up @@ -307,7 +315,7 @@ public NGSessionStore sessionStore() {
public NGResponse dispatchRequest( final NGRequest request ) {

try {
cleanupWOURL( request );
rewriteURL( request );

final NGResponse response;

Expand Down Expand Up @@ -454,20 +462,19 @@ public NGActionResults defaultResponse( final NGRequest request ) {
}

/**
* FIXME: Well this is horrid // Hugi 2021-11-20
*
* What we're doing here is allowing for the WO URL structure, which is somewhat required to work with the WO Apache Adaptor.
* Ideally, we don't want to prefix URLs at all, instead just handling requests at root level. But to begin with, perhaps we can
* just allow for certain "prefix patterns" to mask out the WO part of the URL and hide it from the app. It might even be a useful
* little feature on it's own.
*/
private void cleanupWOURL( final NGRequest request ) {
private void rewriteURL( final NGRequest request ) {

final Pattern pattern = Pattern.compile( "^/(cgi-bin|Apps)/WebObjects/" + properties().propWOApplicationName() + ".woa(/[0-9])?" );
final Matcher matcher = pattern.matcher( request.uri() );
for( Pattern pattern : urlRewritePatterns ) {
final Matcher matcher = pattern.matcher( request.uri() );

if( matcher.find() ) {
request.setURI( request.uri().substring( matcher.group().length() ) );
if( matcher.find() ) {
request.setURI( request.uri().substring( matcher.group().length() ) );
}
}
}

Expand Down

0 comments on commit bcb0a4c

Please sign in to comment.