how to access assets/images from the view in Sails.js? - html

I simply want to add an image in a view in my Sails-Project
My view-file has the location
views/album/albums.ejs
and the image is located in
assets/images/placeholder.png
if I add the image like this
<img src="../../assets/images/placeholder.png">
I get this error
GET http://localhost:1337/assets/images/placeholder.png 404 (Not Found)
Am I missing something?

Sails use Grunt (Gruntfile.js in root of project) to execute some tasks during sails lift. One of that tasks is to copy files from assets directory to .tmp/public/ directory (in development version). So if u add your file to assets directory you will need to restart sails (sails lift) to get it accessible from .tmp/public/ (what is public accessible directory root). Also its important to note that if u put files directly to .tmp/public/ it will be accessible instant, but on next sails lift it will be deleted, since one of Grunt tasks is to clear that directory before copy new files. All of this u can find on sails documentation (assets and asset-management) and by reading Gruntfile.js in root of your project

<img src="/images/placeholder.png">
should work. the assets folder is the equivalent to adding a folder with the static middleware in express.
asset documentation

Looks like you have grunt hook removed.
When removing the grunt hook you must also specify the following in .sailsrc in order for your assets to be served, otherwise all assets will return a 404.
{
"paths": {
"public": "assets"
}
}

I was also facing the same problem.
In sails version 0.12.0,
I was trying to show an image from assets folder to homepage.ejs.
Then by using below img tag, it solved my problem.
<img src="/images/placeholder.png" width="30px" height="30px">
But as your ejs file is inside views/album/albums.ejs
I may suggest, below may work
<img src="../images/placeholder.png" width="30px" height="30px">
But the right approach in sails ejs pages is,
<img src="/images/placeholder.png" width="30px" height="30px">
This must work for you also.

If you have the tasks/sync.js file in your project, add the following object in files array:
{
cwd: './assets/images',
src: ['**/*.*'],
dest: '.tmp/public/images'
}
you need to have sails-hook-grunt and grunt-sync installed.

Related

elasticbeanstalk won't set virtual paths

I am trying the new AWS Elastic Beanstalk console ui. I am having a problem now to set up virtual paths on ui.
Basically I put all my static files, including index.html in a folder ui inside my bundle.
This is the bundle structure:
/ui
/ui/favicon.ico
/ui/index.html
/ui/static
/ui/static/css/...
/ui/static/js/...
/ui/static/media/...
package.json
yarn.lock
app.js // this is the node api and it works
The API works when access my [http://public]/api/alive. My intention is set virtual directories to serve static files from bundle folder ui.
The node api sends down the index.html when it doesn't match anything. This works: [http://public]/. I get the index.html.
Then the browser requests static files /static/js/main[hash].js. This works but the problem is I can't even set up any virtual path to play around. I need to map the browser request /static to /ui/static at AWS.
elasticbeanstalk error:
/static/: Invalid option specification (Namespace: 'aws:elasticbeanstalk:container:python:staticfiles', OptionName: '/static/'): Unknown configuration setting.
static/: Invalid option specification (Namespace: 'aws:elasticbeanstalk:container:python:staticfiles', OptionName: 'static/'): Unknown configuration setting.
/assets: Invalid option specification (Namespace: 'aws:elasticbeanstalk:container:python:staticfiles', OptionName: '/assets'): Unknown configuration setting.
static: Invalid option specification (Namespace: 'aws:elasticbeanstalk:container:python:staticfiles', OptionName: 'static'): Unknown configuration setting.
No matter where I put the slashes, it wont work:
All the paths I specified exist inside my deployed app bundle, apart from /static/assets which is just to try anything different.
I am not sure if this is a bug on the new UI or not. If anyone had the same problem please let me know.
I found this question while trying to serve static content from a Python 3.7 Django application using Amazon Linux 2; however, I think the answer will be the same for different platforms.
Reading the documentation here I found this link: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-cfg-staticfiles.html
which indicated a .config sample file like this
Example .ebextensions/static-files.config
option_settings:
aws:elasticbeanstalk:environment:proxy:staticfiles:
/html: statichtml <-- path/to/your/static/dir/ (added by Nick)
/images: staticimages
so, it looks like the namespace changed from aws:elasticbeanstalk:container:python:staticfiles to aws:elasticbeanstalk:environment:proxy:staticfiles. This seems to be a more generic reverse proxy to be platform agnostic which makes sense. Good job AWS.
When I tried this, amazingly the documentation was up to date and it worked.
Just to elaborate on Nick's answer- the /html or /images here will correspond to the path where your environment expects to receive the files.
So if you open up the network tab of your browser console and see something like:
404 GET http://your.app.com/static/admin/css/base.css
Then you probably want the path to be /static instead of /html
The value statichtml will correspond to the location of the static files on your eb instance.
So, if you run eb ssh and then manage.py collectstatic and get an output like this:
You have requested to collect static files at the destination
location as specified in your settings:
/var/app/current/static
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Then you probably want the value to be /static/

Debug common typescript project in Visual Code

I am new to typescript and I am trying to do something that seems like it should be easy but no one on my team has got it to work and I can't find an answer online.
I have a common folder with shared components that I package with gulp, I then have an application folder that uses this package.
So the structure is something like
root
AppName
node_modules
CommonUi (with javascript)
src
..files..
CommonUi
node_modules
src
..files..
What I would like to do is run AppName and be able to put breakpoints in the typescript in CommonUi, if I debug CommonUi (point at the AppName url) the breakponits are disabled.
I assume I need a configuration setting to point at the CommonUi\src folder but I don't know where to put it.
Can anyone tell me what I need to do?
Thanks, Vincent

How can I handle html files in Luminus which aren't in "resources"?

I have this:
(defn about-page []
(layout/render "about.html" {:title "About"}))
But since I have moved the directory "templates" from "resources" to the root directory and on a server I might put it yet in another place, it doesn't work. I did it because I don't want the html templates to be embedded in the output jar.
So how can I make the code work, how can I get access to my html files in "templates" then?
And the same question for static images, css, js: I put them in the root directory for now, so they aren't in "resources". They're in "public" folder. However, when I refer to them as "public/css/css1.css", they aren't getting found, that is, the path localhost:3000/public/css/css1.css doesn't exist.
How can I tell Luminus where my statics are located now?
Templates location
Selmer's documentation describes how to change the location of the templates:
By default the templates are located relative to the ClassLoader URL.
If you'd like to set a custom location for the templates, you can use
selmer.parser/set-resource-path! to do that:
(selmer.parser/set-resource-path! "/var/html/templates/")
It's also
possible to set the root template path in a location relative to the
resource path of the application:
(set-resource-path! (clojure.java.io/resource "META-INF/foo/templates"))
This allows the templates to be refrerenced
using include and extends tags without having to specify the full
path.
To reset the resource path back to the default simply pass it a nil:
(selmer.parser/set-resource-path! nil)
The application will then look
for templates at this location. This can be useful if you're deploying
the application as a jar and would like to be able to modify the HTML
without having to redeploy it.
As you want your templates to be reload when you change them you should also remember that Selmer caches them:
When rendering files Selmer will cache the compiled template. A
recompile will be triggered if the last modified timestamp of the file
changes. Note that changes in files referenced by the template will
not trigger a recompile. This means that if your template extends or
includes other templates you must touch the file that's being rendered
for changes to take effect.
Alternatively you can turn caching on and off using
(selmer.parser/cache-on!) and (selmer.parser/cache-off!) respectively.
Assets location
Handling of static resources is configured using site-defaults in your <app>.middleware namespace. You need to configure its' :static entry to use :files instead:
(-> site-defaults
(assoc :static {:files "/var/www/html"}))
and you need to copy files from resources/public directory to that location.

ViewHelper is not found

I fiddled around with it for more than 8 hours without getting it resolved.
All I want is to call a ViewHelper in a Fluid template. I did that before and I never had a similar problem.
My ViewHelper file is located in
EXTDIR/VendorName/Classes/ViewHelpers/SomeViewHelper.php.
In my Fluid Template I use the namespace
{namespace k=VendorName\Extname\ViewHelpers}.
Somewhere in the template I call the ViewHelper with
{k:some()}.
The ViewHelper script "SomeViewHelper.php" contains the following code:
class SomeViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
public function initializeArguments() { }
public function render() {
return 7;
}
}
As you can see, the whole thing is quite simple and the expected output on the page should be "7". But calling a page in the frontend produces this error message:
Oops, an error occurred!
Could not analyse class:VendorName\Extname\ViewHelpers\SomeViewHelper maybe not loaded
or no autoloader?"
Any hints on what might be wrong here?
Cheers
Michael
If everything is spelled correct, and even after deleting System/Configuration Cache the ViewHelper doesn't come up (Could not analyse.. / maybe not loaded or no autoloader), try to reinstall the extension in extension manager!
Your path to the viewHelper source file is wrong.
The correct path should be (without vendorname):
EXTDIR/Classes/ViewHelpers/SomeViewHelper.php
You also need to make sure, you use the correct namespace for your viewHelper (if you're on TYPO3 6+, don't use the old Tx_ classes but namespaces).
<?php
namespace VendorName\Extname\ViewHelpers;
class SomeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
public function initializeArguments() { }
public function render() {
return 7;
}
}
The error message seems to indicate that the class is not found.
Without more info, I would probably suspect a typo somewhere (pun not intended).
The following assumes you are using TYPO3 7 and not composer mode:
First, please check if your viewhelper class is autoloaded. This will help to narrow down the problem. On the command line in the htdocs directory: grep SomeViewHelper typo3temp/autoload/autoload_classmap.php This should give you a hit, if the ViewHelper class is included in the autoload file.
If the classes are not autoloaded, you might manually want to do the autoloading: On the command line in the htdocs directory: php typo3/cli_dispatch.phpsh extbase extension:dumpclassloadinginformation
For more information see: https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Autoloading/Index.html. For more in depth info see this: http://insight.helhum.io/post/130876393595/how-to-configure-class-loading-for-extensions-in You can find this functionality of autoloading in the install tool in TYPO3 8, so in that case you would not need to run the command on the command line.
If this does not work either, check the following:
Are you using namespace correctly in the class: <?php namespace VendorName\Extname\ViewHelpers\SomeViewHelper;
Is the path (including Camelcase class name) correct: /Classes/ViewHelpers/SomeViewHelper.php
After that, clear the system cache and reinitiate the autoloading as described above.
In order for the autoloading to be initiated automatically, you might have to update your ext_emconf.php (if you are not using composer mode) or composer.json (if you are using composer mode).
Just some questions:
Did you add the TypoScript Template of the Extension to the Static Includes?
If you're using a unix-alike system, are you sure that your webserver has the permission to read that files?
If TYPO3 is installed in composer mode and your extension is not installed via composer (e.g. a ProviderExtension of FluidTYPO3), you must provide autoload information for your extension in the main composer.json file, as described within TYPO3-composer-documentation:
In Composer Mode all class loading information must be provided by each of the installed extensions or the root package. If TYPO3 extensions are not installed by composer, e.g. because they are directly committed to the root package or a new package is kickstarted, class loading information needs to be provided, otherwise no classes can be loaded for these extensions/ packages.
E.g. if you have a site extension directly committed to your root package, you must include the class loading information in the root package like that:
Drove me crazy to get my ViewHelpers autoloaded. Providing the autoload-information within a composer.json or the ext_emconf.php of the extension and reinstalling it didn't do the trick.

Cocoa Pods and Google Maps SDK

When using CocoaPods to get the Google Maps SDK for iOS, I'm having troubles importing the sdk header file (#import <GoogleMaps/GoogleMaps.h>).
I'm new to CocoaPods but I think I have everything working fine with the other libraries that I use (RestKit, AFNetworking...).
For these APIs I still need to import the lib like this #import <AFNetworking/AFNetworking.h> instead of just #import "AFNetworking". But it works fine.
For Google Maps SDK I need to import it like this #import <Google-Maps-iOS-SDK/GoogleMaps/GoogleMaps.h> which leads to a compilation error because in the GoogleMaps.h header the other files are imported like this:
#import <GoogleMaps/GMSCameraPosition.h>
#import <GoogleMaps/GMSCameraUpdate.h>
#import <GoogleMaps/GMSCircle.h>
...
Did I miss something?
You should not have to import anything linked with CocoaPods using < and >. It should simply be #import "Foo.h". In the case of Google Maps based on my test project I just had to use #import "GoogleMaps.h" and it imported correctly. Make sure you're installing with the newest version of CocoaPods (pod --version currently 0.21.0) otherwise you may need to update it ([sudo] gem update). Also make sure you're opening the created xcworkspace file instead of the xcodeproject
I ran into the same issue(and am using cocoapods), specifically where the error "GoogleMaps.h" file not found. My solution(if the above fails to work), is that your Pods' Target Support Files fail to include the correct header path for "GoogleMaps.h".
Step #1
If you examine your project directory in Finder, click on Pods directory, then Public directory, then GoogleMaps directory, you'll notice that there is a second GoogleMaps directory. Inside that second GoogleMaps directory contains the header files pertaining to the GoogleMaps pod. Now time to check that Pods target support files have this path as the header path for GoogleMaps.
Step #2
Close Xcode Project. Go to the parent directory of your project. For me, it's my home directory, which can be reached at cd ~. Traverse into your Pods' Target support files:
cd ~/{your_project_name}/Pods/Target Support Files/Pods
Then open up your Pods.debug.xcconfig file in your favorite editor:
vi Pods.debug.xcconfig
Edit the line
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/GoogleMaps"
with the new header path
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/GoogleMaps/GoogleMaps"
Leave the rest of the Pods.debug.xcconfig untouched. Follow this same process for Pods.release.xcconfig.
Step #3
Re-open your .xcworkspace file. Clean your project(cmd-shift-k) and then re-build(cmd-b).