I'm trying to use javascriptRoutes in Play 2 (Scala) and I am getting an error (see below). Here is what I did:
Add javascriptRoutes method to Application controller
def javascriptRoutes = Action { implicit request =>
import routes.javascript._
Ok(Routes.javascriptRouter("jsRoutes")(Orders.searchProducts))
.as("text/javascript")
}
Add route to routes file
GET /assets/javascripts/routes controllers.Application.javascriptRoutes
Add <script> import to main.scala.html
<head>
...
<script type="text/javascript" src="#routes.Application.javascriptRoutes"></script>
...
</head>
With these changes in place I am getting the following error in the JavaScript console:
GET http://localhost:9000/assets/javascripts/routes 404 (Not Found)
Uncaught ReferenceError: jsRoutes is not defined
What am I missing?
wrong order within the conf/routes file may cause the issue.
there is a hint:
http://grokbase.com/t/gg/play-framework/1348rbs2vk/2-1-scala-javascript-router-404
once I adjusted the order according to the hint:
Move the route definition of the javascript router action above the
assets route.
the issue was fixed.
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
GET / controllers.MainController.index()
GET /message controllers.MessageController.getMessage()
GET /assets/javascripts/routes controllers.MessageController.javascriptRoutes()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
GET /webjars/*file controllers.WebJarAssets.at(file)`
In the meantime I have found an other post related to this ->
Unable to resolve reverse routing methods in IntelliJ
I had to remove some info from the project config to get the following folders to become part of source route ->
File -> Project Structure
Select Sources in Right Pane
Add Source folder
target/scala-XXX/classes_managed
target/scala-XXX/src_managed/main
Related
I have blade file named index-game.blade.php. And in one line of it, a line that reaches a js file under laravel public folder.
<script type="text/javascript" src="{{asset('game/')}}/js/CPreloader.js"></script>
So far so good.
Also inside CPreloader.js, I have lines like this.
s_oSpriteLibrary.addSprite("bg_menu","./sprites/bg_menu.jpg");
s_oSpriteLibrary.addSprite("progress_bar","./sprites/progress_bar.png");
At this stage, I get the following error in the console of my browser's devtools screen:
bg_menu.jpg:1 GET http://127.0.0.1:8000/games/sprites/bg_menu.jpg 404 (Not Found)
progress_bar.png:1 GET http://127.0.0.1:8000/games/sprites/progress_bar.png 404 (Not Found)
This is the link where I called "index-game.blade.php" => http://127.0.0.1:8000/games/slot1 (Let's pay attention to the games word here)
It works if i change my javascript file to
s_oSpriteLibrary.addSprite("bg_menu","../game/sprites/bg_menu.jpg");
s_oSpriteLibrary.addSprite("progress_bar","../game/sprites/progress_bar.png");
Because the correct link is this instead
http://127.0.0.1:8000/games/sprites/bg_menu.jpg // wrong
http://127.0.0.1:8000/game/sprites/bg_menu.jpg // true
I don't want to change the paths in all my javascript files. Because this is a game and there are as many pictures as possible. How do I correctly identify the laravel public folder in my external js files.
There is a package for that: https://github.com/tighten/ziggy
Some copy/paste from docs:
Install Ziggy into your Laravel app with
composer require tightenco/ziggy
Generate javascript route file:
php artisan ziggy:generate
Import in js file and use:
// app.js
import route from 'ziggy';
import { Ziggy } from './ziggy';
// ...
route('home', undefined, undefined, Ziggy);
I have a laravel project deployed on a domain subfolder
https://example.com => another project
https://example.com/dashboard => my laravel project
I have set my livewire config asset_url to config('app.url'), which my .env's APP_URL is https://example.com/dashboard
It is a simple project that has an auth middleware which protect https://example.com/dashboard and redirect it to https://example.com/dashboard/login. And when I try to fill the input (it has wire:model attribute), I get an error at my JS console
Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at index.js:58
When I check the Network tab, there were some process:
https://example.com/dashboard/livewire/message/login (post) => 302 (i think it is not expected)
https://example.com/dashboard/login (get) => 200 (i think it makes the error above)
It works fine if I deploy it to https://example.com, but at https://example.com/dashboard it keeps getting this issue
Could you guys help me?
Take a look at the livewire.php config folder, maybe you have to change the path for the Livewire assets
I am loading the view in the package with
$this->loadViewsFrom(__DIR__.'../../resources/views', 'admin');
But when I request the page I get an error
InvalidArgumentException
View [test] not found.
Interesting twist, when I put the complete path to the view folder in the loadViewsFrom method the template loads.
I load the blade template with the following code
public function showTest()
{
return view('admin::test');
}
Right above the loadViewsFrom method, I call loadRoutesFrom method
$this->loadRoutesFrom(__DIR__.'../../routes/admin.php');
And this loads without any issue.
Any suggestions what could be the issue? The code of the package is very plain, load a blade template when a route is called.
The problem was solved by fixing the paths to view folder.
After verifying the exact location of my file by
dd(__DIR__);
I worked my way back to the correct path of the view folder, which was just one folder lower and not to.
i have added sitemap.xml file to my codeigniter project.
And i call it on my localhost like that : http://localhost/demo/sitemap.xml
it runs without any issue.
But when i run it on live server http://example.com/demo/sitemap.xml
it says 404 page not found.
What is issue ?
you need to add below things in your config/routes.php file
$route['sitemap\.xml'] = 'demo/sitemap'; // your navigation path i.e. your controller_name/function_name
So i have an API created with Lumen with some documentation done with Apidoc outside of the public folder and i'd like to serve it when the user goes to the URL http://apidomain.com/docs
This is the structure of the app
ProjectRoot
->API
->Auth
->Docs
->v1
->app
->bootstrap
->database
->public
...
Is there any way to create a route that sends the user to API/Docs?
It's done, it was actually my bad, when trying to call the file via routes it actually messed up the filepath for the other files. So when i looked in the dev tools on chrome i noticed i was getting 404's on my js and css files, hence the failure to load the ApiDoc