LocomotiveCMS 2.2.3 issue assets not loading https - locomotivecms

I'm hosting a locomotiveCMS engine on heroku. I just upgraded the engine to 2.2.3 everything worked fine, except that now all assets are failing to load. After I looked at the source code I saw that all assets (like css, js etc) are referenced via "https" to my s3 bucket and thus not working.
I'm using the liquid tags like "{{ "main" | stylesheet_tag }}" and don't know why they resolve to "https"
Thanks
Nick

I fixed it by adding these 2 lines to following to carrierwave.rb:
config.asset_host = 'http://.s3.amazonaws.com'
config.fog_public = true
CarrierWave.configure do |config|
config.cache_dir = File.join(Rails.root, 'tmp', 'uploads')
case Rails.env.to_sym
when :development
config.storage = :file
config.root = File.join(Rails.root, 'public')
when :production
# the following configuration works for Amazon S3
config.storage = :fog
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['S3_KEY_ID'],
:aws_secret_access_key => ENV['S3_SECRET_KEY'],
:region => ENV['S3_BUCKET_REGION']
}
config.fog_directory = ENV['S3_BUCKET']
config.asset_host = 'http://<my-bucket-name>.s3.amazonaws.com'
config.fog_public = true
else
# settings for the local filesystem
config.storage = :file
config.root = File.join(Rails.root, 'public')
end
end

Related

How to load images in express js hosted on vercel

I am trying to make a GitHub banner generator using express js, my code works fine locally but when I try to host it on vercel all the image files go missing and I get no such file or directory found error.
app.get('/api',async(req,res)=>{
const title = req.query.title || "Github Banner Generator"
const subTitle = req.query.subtitle || ""
const theme = req.query.theme || "default"
const _theme = require(`./themes/${theme}/${theme}.json`)
const image = await loadImage(fs.readFileSync('themes/default/image1.png'))
const img = await new Canvas(1280, 520)
.printImage(image,0,0)
.setColor(_theme.primaryColor)
.setTextFont('bold 60px Serif')
.setTextAlign('center')
.printText(title,1280/2,520/2)
.setTextFont('20px Serif')
.setTextAlign('center')
.printText(subTitle,1280/2,(520/2)+60)
.toBuffer();
res.set({'Content-Type':'image/png'})
res.send(img)
})
I think the image path isn't right because of you didn't used an absolute path. You should read more about the difference between ./ and __dirname in NodeJS.
My solution would be to use __dirname + (the file location depending on the current file folder)
const image = await loadImage(fs.readFileSync(__dirname
+ '/themes/default/image1.png'));
Here, I assume that your project structure looks something like this...
/package.json
/index.js (contains the code)
/themes/default/image1.png

Unable to load css referenced assets with wkwebview

Swift 5 wkwebview appears to ignore requests for relative files from css referenced assets / images / fonts. inline nor .css files work.
This happens regardless if using the local bundle paths or a website stored in its own folder in the app documents.
Javascript runs fine, however all relative file calls in css fail.
I've set the baseURL to the appropriate folder, and many direct-linked files work fine. Just not css relative pathed referenced assets.
Background images and fonts do not load when referenced in a css file using relative file paths, example:
background-image: url("images/background.jpg");
background-image: url("/images/background.jpg");
All relative referenced files fail from css calls. Checked via safari debug of the application.
In the main bundle I have an www folder where the following folder structure is:
www/
www/index.html ( references all support files relative path - works )
www/css/style.css ( references image and font assets relative path - fails )
www/js/main.js
www/images/background.jpg
www/fonts/ { various fonts }
This exact folder is also copied to the app's document folder to test loading from the documents folder over a main bundle resource folder. Both fail.
I've tested and verified the above web app using a node http server, no issues.
In both cases, the actual HTML loads, and relative path javascript and css files load, javascript runs fine, however all files referenced within the style.css in relative path form do not load.
Using safari on the emulated iOS device I can see the working files that are referenced are given a system file reference for loading instead of relative paths, re:
file:///Users/{ username }/Library/Developer/CoreSimulator/Devices/ {...device serial number... }/data/Containers/Bundle/Application/{ ... application serial ... }/webtest.app/www/css/index.css
However the failed .css referenced files are referenced as:
file:///images/background.jpg
So baseURL doesn't seem to work or is ignored?
Example funcs - both do not work regarding this issue:
func loadLocalURL(refDir: String, entryPt: String, ext: String, param: String? = nil) -> Void {
let sUrl: String = entryPt + (param != nil ? "/?\(String(describing: param))" : "")
do {
let url = Bundle.main.url(
forResource: sUrl,
withExtension: ext,
subdirectory: refDir)
if (url != nil) {
let request = URLRequest(url: url!)
self.webView.load(request)
} else {
print("FAILED. URL: \(refDir)/\(sUrl).\(ext)")
}
} catch {
print("ERROR LOADING APP AT \(refDir)\(sUrl)\nerror: \(error) ")
return
}
}
func loadLocalDocsURL(url: URL, entryPoint: String) {
let folderURL = url.deletingPathExtension()
let htmlPath = folderURL.appendingPathComponent(entryPoint).path
let folderPath = folderURL.path
let baseUrl = URL(fileURLWithPath: folderPath, isDirectory: true)
let htmlURL = URL(fileURLWithPath: htmlPath, isDirectory: false)
self.webView.allowsBackForwardNavigationGestures = false
// self.webView.loadFileURL(htmlURL, allowingReadAccessTo: baseUrl) // Same asset relative path problem
self.webView.loadHTMLString(try! String(contentsOf: htmlURL), baseURL: htmlURL.deletingLastPathComponent()) // same relative path app problem
self.view = self.webView
}
Per documentation I expect that once a baseURL is set, the relative path requests should service just as if it were served via http service.

Node-Red custom node_modules location

I'm using node-red as embedded in my Express.js application like this
https://nodered.org/docs/embedding. When embedded like this node-red cant load new nodes from npm.
Issue is that when defining custom user dir in settings.js, for example userDir: 'node-red-data/' Node-red adds loaded nodes to this folder inside node_modules.
So I have two node_modules folder:
myapp/node_modules => this is containing node-red
myapp/node-red-data/node_modules => this is containing node-red extra nodes
Some how node-red can't load modules in side myapp/node-red-data/node_modules
Is there any solutions?
Issue was on the settings file.
My setting in user dir:
var settings = {
httpAdminRoot: '/admin',
httpNodeRoot: '/ap',
nodesDir: '/nodes',
flowFile: "flows.json",
userDir: './data/'
}
Right setup:
var path = require('path');
var dir = path.dirname(__filename);
var settings = {
httpAdminRoot: '/admin',
httpNodeRoot: '/ap',
nodesDir: dir + '/nodes',
flowFile: "flows.json",
userDir: dir+'/data/'
}
So adding static path to user dir and nodes dir makes it working
I have similar problem.
I used process.execPath
userdir = path.resolve(process.execPath,'..'); //better that __dirname;
Because the dir is diferent when application is compiled.
// Create the settings object - see default settings.js file for other options
var settings = {
verbose: true,
httpAdminRoot:"/admin",
httpNodeRoot: "/",
userDir: userdir, // problem with dir...
flowFile: 'flows.json',
};

Link to reading, editing and saving INI files in node js

I tried searching for an entire day. Either i am blind or there is no specific answer to my question. How do i do it? I'm developing a steam bot in node js and i want to load accounts - username, pass etc.. of couple of accounts from .ini file. After a long time searching i only found how to read from an .ini file using node-ini module.
var ini = require('node-ini');
ini.parse('./config.ini', function(err,data){
console.log( data.Admin.pass ); //working.
data.Admin.pass = '1136'; //not working how to change value in ini.
data.Admin.H = 'test'; //not working as well.
});
This library (https://github.com/npm/ini) is a good option to do what you are looking to achieve.
Checkout this example from the docs:
var fs = require('fs')
, ini = require('ini')
var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))
config.scope = 'local'
config.database.database = 'use_another_database'
config.paths.default.tmpdir = '/tmp'
delete config.paths.default.datadir
config.paths.default.array.push('fourth value')
fs.writeFileSync('./config_modified.ini', ini.stringify(config, { section: 'section' }))

Using directory (for images links etc) in Openshift (nodejs application)

I have a webpage that I have hosted using a node application on openshift. Its here
http://nodejs-volition.rhcloud.com/
My question is very simple (although I haven't found anyone else asking it). How do I refer to other files in the directory which contains index.html
For instance I would like to use an image that is in the directory in the index. My current html for the image is
<img src="$OPENSHIFT_REPO_DIR/images/1416870991752.jpg" alt="spark core">
I have also tried using "images/1416870991752.jpg". I have the same problem with linking to other html files in the directory?
What am I doing wrong? Please help?
As corey112358 alludes to below the key is in that to host using nodejs a server must be defined. My application already has a server file, so rather than creating a new server I must modify the existing one. I've done it successfully now, there were two changes to make to the server.js file.
The 1st change is modification of the cache. That should look like this...
self.zcache['index.html'] = fs.readFileSync('./index.html');
self.zcache['page2.html'] = fs.readFileSync('./page2.html');
self.zcache['sparkcoredark.jpg'] = fs.readFileSync('./sparkcoredark.jpg');
The first line was already included but the next two were added by me to include another html page and an image.
The second step is modify the self.createRoutes section of the server.js file as below (asciimo image is included by default).
self.createRoutes = function() {
self.routes = { };
self.routes['/asciimo'] = function(req, res) {
var link = "http://i.imgur.com/kmbjB.png";
res.send("<html><body><img src='" + link + "'></body></html>");
};
self.routes['/'] = function(req, res) {
res.setHeader('Content-Type', 'text/html');
res.send(self.cache_get('index.html') );
};
self.routes['/page2.html'] = function(req, res) {
res.setHeader('Content-Type', 'text/html');
res.send(self.cache_get('page2.html') );
};
self.routes['/sparkcoredark.jpg'] = function(req, res) {
res.setHeader('Content-Type', 'image/jpg');
res.send(self.cache_get('sparkcoredark.jpg') );
};
};
Hope that helps out anyone else struggling with this issue. Thanks to coreyfibonacci

Resources