Package Vue frontend in Go binary - go

I am trying to serve my frontend using the Gin framework. It is a small project which would make maintenance easier having it as a single binary.
The project structure looks like this:
Project
|
+-- backend
| |
| +-- backend (binary)
|
+-- frontend
| |
| +-- dist
| |
| +-- package.json
|
+-- Procfile
|
+-- .gitlab-ci.yml
Currently I am serving the fronend like this:
r.Use(static.Serve("/", static.LocalFile("../frontend/dist", false)))
For local dev this works fine and I did not have any issues. If I deploy this with my gitlab-ci pipeline it fails as I do not upload the ../frontend/dist directory. I looked at the pkgr library which should help me achieve my goal.
My issue is I can not get it to work with the Gin framework. Current snippet:
test := pkger.Dir("../frontend/dist")
r.Use(static.Serve("/", static.LocalFile("../frontend/dist", false))) <- compiles but does not serve frontend
r.Use(static.Serve("/", static.LocalFile(test, false))) <- Does not compile
Is there an easier way to achieve my goal?

The problem is when you deploy the project to Heroku (I supposed you are using Heroku because of the tag you are using) it compiles the Go to a binary.
The binary is running in the root folder of the project and ../frontend is not in the same path as the development enviroment anymore.
Something like this:
Project
|
+-- backend
| |
| +-- backend (binary)
|
+-- frontend
| |
| +-- dist
| |
| +-- package.json
|
+-- Procfile
|
+-- .gitlab-ci.yml
|
+-- project binary <---- here
So the correct path is ./frontend/ (see one dot)
You can set an environment variable to set the correct path.
As you are using Vue, you can set for the development environment a dev-server with a proxy pointing to backend. Then when building for production you can make Vue compiles to a specific folder that is hardcoded and served by the backend.

Related

How to specify Dapr component locations with Sidekick?

I'm trying to get started with Sidekick for Dapr, and am having trouble telling Sidekick where the dapr components are.
By default it's going to %USERPROFILE%.dapr\components, but I'd rather it go to a folder local to the solution.
Looking at the code it appears that adding the following to the appsettings.json should work, but it isn't picked up.
"DaprSidekick": {
"RuntimeDirectory": "dapr",
"ComponentsDirectory": "C:\\Dev\\DaprPOC\\components",
}
However the components folder invariably becomes %USERPROFILE%\.dapr\components
Any help on how I specify the component locations with Sidekick?
When you set "RuntimeDirectory": "dapr" Sidekick will automatically look for component files in the dapr/components subdirectory in your solution. Try removing the ComponentsDirectory entry so it returns to defaults, and try a directory structure like this:
|-- MyProject
| |-- MyProject.csproj
| |-- dapr
| | |-- config.yaml
| | |-- components
| | | |-- my_component.yaml
The Dapr Sidecar should then load my_component.yaml.
You can also manually add the components directory in the dependency injection:
services.AddDaprSidekick(configuration, p => p.Sidecar =
new DaprSidecarOptions() { AppId = "daprservice", ComponentsDirectory = "C:\\Dev\\DaprPOC\\components" });

Pod install clone the repository multiple times if you use single repo for multiple Podspecs

Hi I have a problem with my repository. I am using single repo for multiple frameworks.
+-- Framework1.podspec
+-- Framework2.podspec
+-- libs
| +-- Framework1
| | +-- File.swift
| +-- Framework2
| | +-- File.swift
Framework1.podspec points File.swift that under the Framework1 folder
Framework2.podspec points File.swift that under the Framework2 folder
In a sample project I am using both
pod Framework1
pod Framework2
When I run pod install --verbose I am seeing that the entire repository is being downloaded twice which is a problem to me because both File.swifts are huge (around 200mb).
Is there a way to download the repository only once?
P.S. I tried to use subspecs but it didn't work. I got duplicated file File.swift error.

Override an existing Blade directive

I'm building a system that implements an inherited template system using Blade. Depending on where the user is, a different view will be loaded.
The system works well, where I have a default 'theme', which contains all views and components for everything the website uses. I don't use the default view method in my controllers, I instead use my own function which works in the same way as view but instead attempts to load the view in the lowest part of the hierarchy and then works its way up until it lands on the default.
For example, my view structure looks like:
+-- views
| +-- frontend
| +-- default
| +-- home.blade.php
| +-- test.blade.php
| +-- site1
| +-- en-gb
| +-- home.blade.php
| +-- en-de
| +-- home.blade.php
| +-- site2
| +-- en-gb
| +-- home.blade.php
This works well. I can call custom_view('home'); and based on certain circumstances the correct view will be shown. In the above example if I call custom_view('test') my system will check the correct folder for the site and locale, and if the view doesn't exist then the default fallback will be used.
My problem comes when I want to use Laravel directives for loading view partials in my code. The three directives that are troublesome are:
#each(), #include() and #component().
I would like to override these directives and have them look up the file from the appropriate sub-directory in my view structure first.
How can I override Blade directives?

Create a war containing only image

I'm trying to create a war that is to be deployed in an EAR and that should contain only images.
My war source organization is as follows :
+---src
| +---main
| | +---java
| | +---resources
| | | \---META-INF
| | | \---resources
| | | \---images
| | | placeholder_image.jpg
| | | placeholder_template.png
| | |
| | \---webapp
| | \---WEB-INF
| \---test
| +---java
| \---resources
and my war effective organization is
+---META-INF
\---WEB-INF
\---classes
\---META-INF
\---resources
\---images
placeholder_image.jpg
placeholder_template.png
The images I want to serve are in the src/main/resources/META-INF/resources/images folder.
I package this war using maven-war-plugin.
Under which url will those images be available on my local machine, provided my war is indicated as available under the http://localhost:8080/myapp/ path ?
None. Content from WEB-INF is not statically served, resources is for classpath resources. You need to put the images (folder) directly under webapp or add an servlet that serves the content.
This depends on whether you deploy the war in a Servlet-3-compatible container like Tomcat 7 or Jetty 8.
If so, your resources should be visible under http://localhost:8080/myapp/images/....
See also this post, where the only difference is that the resources are packaged in a jar. For jars, this feature makes more sense than for WEB-INF/classes, as, like the first answer points out, you should simply put your resources directly into src/main/webapp if they are located in the same Maven module.

Rails 3.1 asset pipeline vendor/assets folder organization

I'm using the jQuery Tools scrollable library in my Rails 3.1 site with the various assets placed in the vendor/assets folder and it works great.
My question is regarding the best way to organize the various files under vendor/assets. What is the recommended way to organize vendor/assets subfolders? Currently I have this structure:
vendor/assets/
|-- images/
| |-- scrollable/
| <various button/gradient images>
|-- javascripts/
| |-- scrollable/
| jquery.tools.min.js
|-- stylesheets/
| |-- scrollable/
| scrollable-buttons.css
| scrollable-horizontal.css
This is a fairly un-DRY what to do this. I feel that all of the 'scrollable' items should be under one folder.
What is the recommended way to do this without having to manipulate the asset pipeline load paths?
Thanks!
You could organise them this way, which is slightly better in that it keeps stuff related to the plugin in one directory:
vendor/assets/scrollable
|-- images/
| |-- <various button/gradient images>
|-- javascripts/
| |-- jquery.tools.min.js
|-- stylesheets/
| |-- scrollable-buttons.css
| scrollable-horizontal.css
I am pretty sure this will work as rails globs all directories under assets/.

Resources