Coldbox and VueJS untangled

Category: Coldbox (Page 1 of 3)

Dynamic datasources part 1: QB

Recently I was working on a project where we wanted to reuse our code for multiple customers. The only difference: they all have their own database where their data was stored. We can do this in two different ways

  • deploy a new application for every customer. For a smal amount of customers that might be acceptable.
  • Based on the url we can detect which datasource we need for a customer. If we would be using the same url for all customers, we can have some central database which keeps all kind of information including datasource name for each individual customer. We could store the datasource name in a private request collection variable called mainDatasource (or put it in some user specific cache or session variable), so each customer has his own datasource.

Since our project was existing code, I have a few hundred references to <cfquery> and queryExecute and many queryBuilder (qb) calls for newer code.

Continue reading

Module dependencies in interceptors

Interceptors in coldbox are very powerful. They are components which listen to events which are announced by the core framework or modules or custom events created by your application. But this post is not about all details of creating interceptors, you can read all about it in the coldbox documentation. I am using them all the time since they are so powerful, but sometimes they don’t behave as expected, especially when your interceptor depends on other modules.

Ahh yes, the good ol chicken and the egg problem

Luis Majano

So, what’s the problem with this chicken and her egg? Actually there are two related problems. One of them is easy to solve, the other takes some more effort.

Continue reading

Scheduled tasks in Coldbox

I often post about problematic stuff, like bugs, incomplete documentation or other annoyances. This post is different, and not even very detailed. We are talking about scheduling tasks. Luis Majano recently described the coldbox 6.4.0 release, which is mainly about scheduling. There is extensive documentation but scheduling is now so easy to code, I just wanted to share some examples with you. Coldbox 6.4 was only released a few weeks ago, but I think is is so extremely useful, we already implemented it in several projects. Ok, there was one bug which I will share with you, but that will be fixed soon, and is easy to avoid.

Continue reading

Closures vs lambda expressions

Yes, if you ever read my twitter profile, I am a bit old fashioned. I started writing CFML when it was still called DBML loooooong ago. Javascript was still simple, and javascript frameworks were eh… nonexisting? So don’t expect me to explain you everything about closures and lambda expressions. But they are not the same in CFML, that’s what I found out today. The hard way.

Continue reading

Problem Details for HTTP APIs: Modifying your Coldbox REST handler response

Coldbox had a base handler and response for RESTful services for many years. Initially this was added in application templates but in version 6 this functionality was added to the core. The base handler wraps around your own actions and provides a lot of automatic errorhandling, addition of some development headers and some global headers. By using the default event.getResponse() response (available as prc.response in previous versions) it provides a default response format which looks like this:

{
    "data": {
        "name": "someData"
        "id": "98765",
        "name": "provMan"
    },
    "error": false,
    "pagination": {
         "totalPages": 1,
         "maxRows": 0,
         "offset": 0,
         "page": 1,
         "totalRecords": 0
    },
    "messages": []
}

That’s a lot of different keys for a default response format. The data field makes sense most of the time, and the pagination key (which is new in cb6) can be handy but we don’t use it (yet). The error and messages keys are less useful to us. Let me explain why first, and then I will explain how to modify your responses in coldbox 6.

Continue reading

cbi18n-json-resources: localization with JSON resources

This week I created my first official forgebox package: cbi18n-json-resources , a cbi18n JSON ResourceService. This module tries to improve the cbi18n Ortus module by offering

  • json resource files instead of java resources
  • locales organized by directory instead of partial filenames
  • optional default resource file(s)
  • hierarchical resources, so both en_GB and en_US can be handled by the same resource file, except for the different country-specific translations
  • and an interceptor for missing translations

So why this module instead of improving the cbi18n module itself?

Continue reading

Customize your resource routing in Coldbox

In this post I will show you how coldbox can help you creating resourceful routes, how cbswagger shows me that I don’t want the defaults resource() routing method, and how easy it is to create your own method!

If you want to create a REST API in coldbox, you often need to create a lot of routes for this API. So let’s say you want to create endpoints to list, view, update, create and delete a User resource. Following the coldbox manual, I need to implement the following routes:

Continue reading

Configuring SES URL’s on apache and the Coldbox router.

Often when we deploy a coldbox website we fire up commandbox, create a webserver and put NGINX in front to route our application requests to the correct lucee instance. We never experienced any problems when configuring search engine safe (SES) url’s. Just to remind you: instead of writing this

https://mysite.nl/index.cfm?event=myhandler.myaction

we can rewrite this to something more friendly such as

https://mysite4u.nl/myhandler/myaction

So we proxy our request via Nginx to a lucee coldbox application and use some rewrite rules as described in the coldbox manual. Recently we had a slightly different configuration: apache in front of an old-fashioned standard lucee standard install on Linux. Again, we followed instructions in the same coldbox manual but NO success…

Continue reading

Event.buildLink: query params vs path variables

I had some issues with how event.buildlink() in Coldbox is generating a URL. To understand what’s my problem let me introduce the old-fashioned way to hit a coldbox application

http://mysite.ext/index.cfm?event=user&age=30
or
http://mysite.ext/index.cfm?event=user.index&age=30

With some rewrite magic this last form can be written as

http://mysite.ext/user/index&age=30
or even
http://mysite.ext/user/index/age/30

So all four forms are behaving the same, if you apply the correct rewrite rules in your webserver and the default rules in the Coldbox router. The coldbox manual has some info on rewrites for several webservers. So in most cases the web is rewriting your url’s in such a format that coldbox will receive this:

http://mysite.ext/index.cfm?user/index/age/30

Coldbox itself is smart enough to hand this over to the router, which has some default rules enabled which translate the user/index/age/30 to:

  • event = user.index
  • age=30
Continue reading

Cfcookie or cookieStorage?

Coldbox has the cbstorages module which can be used as an API for accessing persistent storage such as cookie, session, application, cache and more. The question is: why should I use such storage if there is cfcookie or something simple as as session struct?

Let me explain with some code. I was working on updating the cbi18n module where we can use session, client, cookie or request scope to store the currently selected locale. In code this is getting ugly soon, with code like this

switch(instance.localeStorage){
  case "session" : { storage = session; break; }
  case "client"  : { storage = client; break;  }
  case "cookie"  : { storage = cookie; break;  }
  case "request" : { storage = request; break; }
}

and in other places in the code:

<!--- Storage of the Locale in the user storage --->
<cfif instance.localeStorage eq "session">
  <cfset session.DefaultLocale = arguments.locale>
<cfelseif instance.localeStorage eq "client">
  <cfset client.DefaultLocale = arguments.locale>
<cfelseif instance.localeStorage eq "request">
  <cfset request.DefaultLocale = arguments.locale>
<cfelse>
  <cfcookie name="DefaultLocale" value="#arguments.locale#" />
</cfif>
Continue reading
« Older posts

© 2021 ShiftInsert.nl

Theme by Anders NorenUp ↑