Enable CORS headers

4 views
Skip to first unread message

iad...@gmail.com

unread,
Jun 6, 2016, 1:29:32 PM6/6/16
to kanbanik
So I have been tasked with the assignment of creating a nice overview web page using Kanbanik as the API.  I am curious as to how I can add in the CORS headers.  I have been tweaking the KanbanikAPI.scala but am having no luck, for some reason I feel that when I compile by running mvn clean install in terminal or by clicking the pom cleaning and installing through Eclipse and then running the application in Eclipse that the program is not actually recompiling and starting the server with the new .war file.

I was trying to do it myself by adding to the process function

  private def process(req: HttpServletRequest, resp: HttpServletResponse) {
    resp.setCharacterEncoding("UTF-8")
    resp.addHeader("Access-Control-Allow-Origin", "*")                                                                                                                                                     
    resp.addHeader("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS")
    resp.addHeader("Access-Control-Allow-Headers","origin, access-control-allow-methods, content-type, access-control-allow-origin, access-control-allow-headers")
    resp.addHeader("Access-Control-Max-Age", "1800")
    
The reason I think that it is not recompiling is because even if I add to the commandWithConfig area of process I get no changes when I make a post/get request to the api via postman

    val commandWithConfig = commands.get(commandName)
    if (!commandWithConfig.isDefined) {
      respondAppError(ErrorDto("Incorrect command name: RECOMPILE! " + commandName), resp)
      return                                                                                                                                                                                               
    }

In postman I just get back "Incorrect command name: "

Thanks guys, I appreciate it!
    


Tomas Jelinek

unread,
Jun 6, 2016, 2:00:05 PM6/6/16
to iad...@gmail.com, kanbanik
hey,

On Mon, Jun 6, 2016 at 7:29 PM, <iad...@gmail.com> wrote:
So I have been tasked with the assignment of creating a nice overview web page using Kanbanik as the API.  I am curious as to how I can add in the CORS headers.  I have been tweaking the KanbanikAPI.scala but am having no luck, for some reason I feel that when I compile by running mvn clean install in terminal or by clicking the pom cleaning and installing through Eclipse and then running the application in Eclipse that the program is not actually recompiling and starting the server with the new .war file.


Are you sure you are running the correct pom.xml? You need to run the parent-most one - the one which is right next to the kanbanik-web, kanbanik-server etc, e.g. this one:
 <groupId>kanbanik</groupId>
 <artifactId>parent</artifactId>

when you compile this just throw it to your server and it should work.

 
I was trying to do it myself by adding to the process function

  private def process(req: HttpServletRequest, resp: HttpServletResponse) {
    resp.setCharacterEncoding("UTF-8")
    resp.addHeader("Access-Control-Allow-Origin", "*")                                                                                                                                                     
    resp.addHeader("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS")
    resp.addHeader("Access-Control-Allow-Headers","origin, access-control-allow-methods, content-type, access-control-allow-origin, access-control-allow-headers")
    resp.addHeader("Access-Control-Max-Age", "1800")

hm interesting. Any chance you could make a pull request when you will make it work?
 
    
The reason I think that it is not recompiling is because even if I add to the commandWithConfig area of process I get no changes when I make a post/get request to the api via postman

    val commandWithConfig = commands.get(commandName)
    if (!commandWithConfig.isDefined) {
      respondAppError(ErrorDto("Incorrect command name: RECOMPILE! " + commandName), resp)
      return                                                                                                                                                                                               
    }

In postman I just get back "Incorrect command name: "

Thanks guys, I appreciate it!
    


--
You received this message because you are subscribed to the Google Groups "kanbanik" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kanbanik+u...@googlegroups.com.
To post to this group, send email to kanb...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kanbanik/3adbc9da-668e-4339-aff1-e768ff5d8ee4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

iad...@gmail.com

unread,
Jun 6, 2016, 2:39:30 PM6/6/16
to kanbanik, iad...@gmail.com, jel...@gmail.com
Yeah, I am indeed using the most parent pom.xml to clean and install.  Even if I do it from the shell at the root, no difference.

I can fully delete the kanbanikAPI.scala file and still have no issues.  But if I drop a typo in there or add a semi colon it won't compile.
By throwing it to the server I am just running it in Eclipse and it's booting up a server for me, is this the wrong attack route?  Should I do it through the shell?  What is your dev enviroment like?  I'm Just having no luck and I've been hacking away at this for a while.  I have no idea what is going on.

And hell yeah I will most definitely be making a pull request once I get this in there.  It's a must for the API :)

iad...@gmail.com

unread,
Jun 6, 2016, 2:50:06 PM6/6/16
to kanbanik, iad...@gmail.com, jel...@gmail.com
Also just so I can assure that I am not insane like the kanbanikAPI.scala file is the one that is handling all requests.  and when I change

    val commandWithConfig = commands.get(commandName)
    if (!commandWithConfig.isDefined) {
      respondAppError(ErrorDto("Incorrect command name: RECOMPILE! " + commandName), resp)
      return                                                                                                                                                                                               
    }

And I do the post request via postman
http://localhost:8080/kanbanik/api?command={"commandName":"please!","userName":"admin","password":"admin"}

I should be getting {"errorMessage":"Incorrect command name:RECOMPILE! please!"}

Instead of just getting {"errorMessage":"Incorrect command name: please!"}

I am sane...right?


Tomas Jelinek

unread,
Jun 6, 2016, 3:15:24 PM6/6/16
to iad...@gmail.com, kanbanik
On Mon, Jun 6, 2016 at 8:39 PM, <iad...@gmail.com> wrote:
Yeah, I am indeed using the most parent pom.xml to clean and install.  Even if I do it from the shell at the root, no difference.

I can fully delete the kanbanikAPI.scala file and still have no issues.  But if I drop a typo in there or add a semi colon it won't compile.
By throwing it to the server I am just running it in Eclipse and it's booting up a server for me, is this the wrong attack route?  Should I do it through the shell?  What is your dev enviroment like?  I'm Just having no luck and I've been hacking away at this for a while.  I have no idea what is going on.

OK, I don't know how eclipse is doing this. What I normally do is to put the kanbanik-web/target/kanbanik.war to my web server. Im using the kanbanik-runtime which you can download and I copy the kanbanik.war into jetty/webapps/ 
I don't normally need more smart devel env - for scala related stuff I either write tests or mostly do it in REPL. And for frontend I just run the super-dev mode and code it like that. So for writing the logic the numerous redeployments are not needed. Which is not your case since you need to fiddle around with the API headers :)

You can try to delete the kanbanik-web/target/kanbanik.war and recompile and check if it gets re-generated. 

One hacky way you could do it to avoid recompiling is to run the server in debug mode, put a breakpoint into the api file and in debug mode add all the headers you need. Hacky, but at least no need to recompile it over and over again :)
 

And hell yeah I will most definitely be making a pull request once I get this in there.  It's a must for the API :)

cool, looking forward :)

iad...@gmail.com

unread,
Jun 6, 2016, 3:36:26 PM6/6/16
to kanbanik, iad...@gmail.com, jel...@gmail.com
Okay, I'm going through the business with Tomcat right now to run everything from the shell and not have to deal with any shady Eclipse BS haha.  Hopefully this will work.  Also where is the kanbanik-runtime located?  I can't find it anywhere through google searches or the project site.

Tomas Jelinek

unread,
Jun 6, 2016, 3:39:02 PM6/6/16
to Michael Alicea, kanbanik
On Mon, Jun 6, 2016 at 9:36 PM, <iad...@gmail.com> wrote:
Okay, I'm going through the business with Tomcat right now to run everything from the shell and not have to deal with any shady Eclipse BS haha.  Hopefully this will work.  Also where

enjoy :)
 
is the kanbanik-runtime located?  I can't find it anywhere through google searches or the project site.

I have just redesigned it :) Don't expect miracles from it, it is just a mongodb, jetty and start and stop script. Very simple.

iad...@gmail.com

unread,
Jun 6, 2016, 3:39:12 PM6/6/16
to kanbanik, iad...@gmail.com, jel...@gmail.com
Clear for take off!!  It was fuc2#$^ Eclipse.  I literally hate working through IDE's for this exact reason haha.  Thanks for the quick replies.  I'll submit that pull requests when I get this baby going!

Tomas Jelinek

unread,
Jun 6, 2016, 3:40:53 PM6/6/16
to Michael Alicea, kanbanik
great! If you will need any help with the code itself just let me know.
(btw I also like to avoid this kinds of features of the IDEs as much as I can :) )
Reply all
Reply to author
Forward
0 new messages