Hi everyone Is it possible to use the same code ...
# box-products
c
Hi everyone Is it possible to use the same code base via CommandBox, using two different engines. Let’s say ACF2021 and the latest version of Lucee. Just to slightly complicate matters, we are wiring CommandBox to IIS, via the AJP BonCode Connector. The codebase webroot will have the same system path, like:
Copy code
C:\domains\<http://acf-lucee.com|acf-lucee.com>\wwwroot\
The reason why it has to use the same system path is because when the application was built, someone hardcoded a system path for many of the mappings in the
Application.cfc
[yes I know. It is legacy code hell 😱] The system path root is:
Copy code
D:\wwwroot
I have had to use
mklink
to create a Junction on this folder, so that it points to:
Copy code
C:\domains\<http://acf-lucee.com|acf-lucee.com>\wwwroot\
So, if I have two different engines powering this codebase, both must point to the same physical address. I can see some of the problems here. How can I make the:
Copy code
server.json
In the the webroot, fire up two different engines? This might work, if I can call `server.json`:
Copy code
server-lucee.json
server-acf.json
Is this possible? In my recipe, how do I tell CommandBox to look for something other than
server.json
c
You can specify the name of the server in each of your 2 json files and use that when starting them:
Copy code
{
  "app": {
    "cfengine": "lucee@5"
  },
  "name": "lucee"
}
Copy code
{
  "app": {
    "cfengine": "adobe@2021"
  },
  "name": "acf"
}
c
Thanks, but I really want to know how to explicitly add a reference to a custom settings file. By default, a recipe like:
Copy code
cd C:\domains\<http://cg-acf-lucee5-3-9_166.com|cg-acf-lucee5-3-9_166.com>\wwwroot\la-api
server set web.http.port=8080
server show web.http.port
server start cfengine=adobe@11.0.19+314546
Will look for
server.json
in _C:\domains\cg-acf-lucee5-3-9_166.com\wwwroot\la-api_ But, I want to change the name of
server.json
to s`erver-lucee.json` How would I reference
server-lucee.json
in the recipe
c
Perfect. Thanks very much. That's just what I wanted...🙂
b
The
serverConfigFile
is what you want
Copy code
server start serverCOnfigFile=/path/to/my-server.json
or, it can be passed as the
name
parameter as a shortcut
Copy code
server start /path/to/my-server.json
Or, if the server's have already been defined, just by name
Copy code
server start myServer
It's also worth noting, if you do
Copy code
server start name=foo
then CommandBox will create a
foo-server.json
instead of a
server.json
🙏 1
You can't bind two servers on the same port and host
That's not how networking works 🙂
You need to minially have two different hosts (IPs) or AJP ports
c
But there is only one BIN folder?
b
Well, that's your problem, lol
how did you instll Boncode?
c
☹️
I just copied the folder
b
that's not how you install boncode
There's an actual installer you tun
If you did a "global" installation, then there will only be one BIN folder and all sites will proxy to the SAME AJP port
I'm actually not entirely sure if you can do what you need to 🤔
c
I installed AJP initially and then I just copy the folder and change
BonCodeAJP13.settings
b
Because even if you have two sites in IIS, they load the BIN by convention
I'm not clear on how IIS uses BIN folders. I don't know if you can create them as a virtual dir or anything or if they must be on disk in the web root
c
I'm actually not entirely sure if you can do what you need to
That's fair enough
b
I installed AJP initially and then I just copy the folder and change
BonCodeAJP13.settings
You're missing what I'm saying. Boncode has TWO ways you can install it • global mode • per-site mode
You need per-site, but I'm not entirely sure if IIS allows you to have two BIN folders if both sites use the same webroot. I'm not an IIS expert on that and I'm really not sure how its BIN folder conventins work
👍 1
c
OK. I wasn't precise enough: I installed AJP initially and then I just copy the folder, between new webroots, and change
BonCodeAJP13.settings
b
When you say "installed AJP", are you talking about something you did in CommandBox, or IIS?
You don't "install AJP" into IIS, but you can "install Boncode", which is an AJP proxy.
c
I installed using the .exe file from AJP
b
Boncode. The library is called Boncode
c
OK. Boncode. Sorry
b
Yes, it's an AJP listener, but CommandBox also has features that use the word AJP so it's ambigious )
That's like when my dad used to call Windows, Word, and Excel by the name "Microsoft" 😆
I'd recommend the following • do some Googling to see what IIS allows in regards to different BIN folders in two sites that share the same webroot • Do some experimentation to see if creating a BIN virtual dir works as a means to allow each site to have a different folder • give up on Boncode and just use IIS request routing to create an HTTP proxy back to CommandBox's HTTP port
👍 1
I recall running into this a few years back and Bilal basically said that wasn't supported if I recall.
Or alternatively, look into the level of effort to refactor the code base away from the hard-coded webroot
👍 1
c
Thanks...
b
Man, 2018 feels so long ago@!
c
I like the virtual directory idea?
Bilal has some workarounds posted on that second ticket, though I don't think I ever tried either of them
👍 1
I would recommend adding a comment on that first ticket as well
c
It will give Bilal's idea a go and let you know how it goes. I will add comments as well...🙏
b
Boncode works well for what it does, but sadly has VERY little development so any bug or enhancements are unlikely to be added.
c
I was just reading through Bilal’s instructions: https://github.com/Bilal-S/iis2tomcat/issues/59
Copy code
Using sub applications

You can achieve a similar outcome with a combination of virtual directories and sub application inside one IIS site. Inside your main site, create web-application as in above link. This will automatically create directories and assign BIN references. You can add the DLL files and Setting files manually, the installer will not copy them for you for sub-applications and manage the connections.

For example

c:\mysite\customer1\BIN
c:\mysite\customer2\BIN

Inside each of sub applications, create virtual path to point to your code:

c:\mysite\customer1\code
c:\mysite\customer2\code

point to

c:\mysite\shared\code
What I don’t understand, is when CommandBox hits:
Copy code
c:\mysite\customer1\server.json
How does it know how to hit:
Copy code
c:\mysite\customer1\code -> c:\mysite\shared\code
There are no CFML files in:
Copy code
c:\mysite\customer1\
Directory structure:
Copy code
c:\mysite\customer1\
|_server.json
|_BIN
|_code -> c:\mysite\shared\code
I know how to set up the virtual directory reference in server.json, but is there another setting that tells CommandBox to hit the virtual directory
c:\mysite\customer1\code
, automatically?
Or does the application server search recursively down through the directories until it hits:
Copy code
index.cfm
As far as I remember, if there are no default CFML files in the webroot, it just shows a list of directories, in the browser?
b
@Charles Robertson I'm not really following your question. The web root in a CommandBox servers is just whatever you've configured as the web root!
Which, by default is the folder the
server.json
lives in unless you've configured a
web.webroot
setting in the server.json to point elsewhere.
c
OK. What I am trying to say is that it seem Bilal is suggesting that the webroot, should ONLY contain the following:
Copy code
c:\mysite\customer1\
|_server.json
|_BIN
|_code -> c:\mysite\shared\code
Because there is no
index.cfm
, what does CommandBox open? I see there is a
server.json
property called
openBrowserURL
Maybe I could set it to:
Copy code
"openBrowserURL" : "<http://mysite.local/code>",
b
@Charles Robertson I think you're over complicating. At the end of the day, COmmandBox needs to see the same web root as IIS. So whatever IIS is serving when you hit
mysite.local
is what CommandBox needs to be serving
Because there is no
index.cfm
, what does CommandBox open?
CommandBox will show a directory listing if there is no welcome file, unless dir listings are disabled, in which case it will return a forbidden page
I'm not really following whatever Bilal's little IIS thing is so all I can say is whatever folder IIS is serving code from in the root of the site needs to be where CommandBox is serving code from. Otherwise, you'll have issues.
👍 1
It's also worth noting, IIS is only serving static files, so if those are limited to just a couple folders, you could just add them as virtual dirs and let the other requests get passed to CommandBox which means the actual IIS web root could be any random folder
c
Thanks for clarifying things. I will try Bilal’s system and then navigate, in the browser, to the virtual directory folder. I think it may still work, even though the dev & production webroots, will be in different locations. So, I will need to navigate to the correct place: Dev websites: http://mysite.local:8081/code [acf] http://mysite.local:8082/code [lucee] Dev directory structure:
Copy code
c:\mysite\acf\
    |_server.json
    |_BIN
    |_code -> c:\mysite\shared\code
c:\mysite\lucee\
    |_server.json
    |_BIN
    |_code -> c:\mysite\shared\code
c:\mysite\shared\code
Prod: http://mysite.com I actually use a similar system on my non work laptop. I put all my production websites in a single wwwroot folder and then navigate to the subfolder. It has never caused a problem.
It’s a bit irritating how this Slack channel, has an edit message time limit? Why is this a good thing? 😡 Rant over 🙂
b
Yeah, I've noticed that too. It's something the mod set and I don't understand why-- it's super annoying
👍 1
I really have no idea what
ExpandPath(".")
is supposed to return, but I've never used that and I don't recommend you use it either. Generally
.
represents the current working directory of a process, but that's not something your CF code should ever be dependent on.
🙏 1
expandPath( '/' )
should resolve to the web root base path
👍 1
c
Yes. It does. Thanks...
I have added this solution to my client’s Wiki [private], but I would like to publish this to the general CFML world. Do you know where I could display this? Although, people can look at Bilal’s solution, it doesn’t really cover the CommandBox side, so it might be useful, if I provide a comprehensive description.
Although I have added an IIS virtual directory, I am not entirely sure, this is required? I haven’t actually had to reference the virtual directory, anywhere, in the CommandBox server.json. Adding a
web.webroot
property to server.json is probably what allows this set-up to work? Anyway, I am going to test this approach, by setting this up again, without the virtual directory. Currently [this works]: server.json:
Copy code
{
    "name":"system_learningassistant_acf",
    "web":{
        "http":{
            "port":"8081"
        },
        "rewrites":{
            "enable":"true"
        },
        "ajp":{
            "enable":"true",
            "port":"8029"
        },
        "host":"system.learningassistant.local",
            "aliases":{
            "/acf-code":"C:\\domains\\acf-lucee-shared\\shared\\la\\Code"
        },
      "webroot": "C:\\domains\\acf-lucee-shared\\shared\\la\\Code"
    },
      "openBrowserURL":"<http://system.learningassistant.local:8081>",
    "app":{
        "cfengine":"adobe@11.0.19+314546"
    },
    "jvm":{
        "javaVersion":"openjdk8_jdk"
    }
}
But I am going to try a version without the
web.aliases
property.
b
Maybe we could have you guest blog it on the Ortus blog as a tutorial
Can you show your IIS setup? I'm curious what virtual directory you have there/
I really like the readabilty of an external text file for complex rules, it's just not as quick and self-contained as putting them in the JSON