Play Swagger UI url alias - scala

I have Swagger UI for API documentation, I use the same approach like in official specification for accessing it I use next URL:
http://localhost:9000/docs/swagger-ui/index.html?url=/assets/swagger.json
But I want to use http://localhost:9000/docs/ instead. I won't want to use WS for delegating, I would like to use single line in routes, like this:
GET /docs controllers.Assets.at(path:String="/public/lib/swagger-ui", file:String="index.html?url=/assets/swagger.json")
Or
GET /docs controllers.Assets.at(path:String="/public/lib/swagger-ui", file:String="index.html")
and http://localhost:9000/docs?url=/assets/swagger.json
What shold I change so it work?

You can't make shortness in route file for the URL /docs/swagger-ui/index.html?url=/assets/swagger.json because index.html is generated by swagger-ui plugin to public directory and requires access to files nearby (like js and css files). Play swagger-ui uses javascript for fetching json based description of your routes via URL parameter for further parsing this document to swagger-ui, in your case it's /assets/swagger.json endpoint.
I tried to make the mapping swagger's index.html file, so pass json location like URL parameter directly:
GET /swagger-ui controllers.Assets.at(path = "/public/lib/swagger-ui", file = "index.html")
Play couldn't render this page, and CSS wasn't found. I appended dummy mapping to every file in swagger's default directory /public/lib/swagger-ui:
GET /*file controllers.Assets.at(path = "/public/lib/swagger-ui", file)
Even after that Play couldn't properly render index.html.

How it can be solved without Play-Swagger:
Create directory public\swagger in your project;
Download all files from https://github.com/swagger-api/swagger-ui/tree/master/dist and copy them to public\swagger;
Copy your swagger.json (it's specification, right?) to public\specification;
Add to your routes file next line:
GET /docs
controllers.Assets.versioned(path="/public/specification", file: Asset
= "swagger.json")

Related

Flutter web download a pdf from API and save in directory

I build a flutter web app and My requirement is to get a file(PDF) and write it in file or download it,
i get my file from an API and it gave me a file not a link,
Can anyone help me with this. An example would be more helpful.
Thank you
Use this utility method:
import 'dart:html' as html;
void openDownloadLink(String href, String filename) {
html.document.createElement('a') as html.AnchorElement
..href = href
..download = filename
..dispatchEvent(html.Event.eventType('MouseEvent', 'click'));
}
Uri getHref() => Uri.parse(html.window.location.href);
The first parameter is the URL of the file to be downloaded, the second is the 'suggested' filename that the browser will show. Note that you can't put in a full path to the local file - the file name is just a suggestion.
The getHref function may be useful. It returns a Uri representing where the Flutter web app was launched from. If you want a path relative to that for your PDF, modify it, keeping the https://server... part the same. Equally, you could probably use a relative path as the href parameter, like ../pdfs/somefile

Scala Play route action can't be found

I don't understand why this isn't working.
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Serve index page from public directory
GET / controllers.HomeController.index
GET /index controllers.FrontendController.index
# An example route (Prefix all API routes with apiPrefix defined in application.conf)
GET /api/summary controllers.HomeController.appSummary
POST /api/getplt/:args controllers.UploadController.getPlt(args)# Serve static assets under public directory
GET /*file controllers.FrontendController.assetOrDefault(file)
Why can't it resolve the action? I can resolve the /api/summary without problems.
First for your assets use the following:
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(file)
Then you could use the assetFinder within your views, something like:
<script src="#assetsFinder.path("javascripts/jquery.js")" type="text/javascript"></script>
This is because try to avoid any similar/identical routes, your first route and the asset related route, looks almost the same.
So to answer your question, either the Play is mixing these two routes, or you dont have index method within your HomeController class.

how to link a html served from a finch/finagle to a fastopt.js on script tag

I am new to scalajs, I have a finch endpoint in my backend project serving a scalatag html generated from frontend project
val apiEndpoints: Endpoint[Response] = get("index") {
val res = Response()
res.setContentString(scalaTagUI.toString())
Future(res)
}
in my Html I have the script tag
script(attr("type"):="text/javascript", attr("src"):="./target/scala-2.12/classes/assets/frontend-jsdeps.js")
The /index is working but it can't access the javascript files giving 404 - I can see the fastopt.js in my target/scala-2.12.....
The solution at the end was simple - I have added a specific endpoint in finch exclusively for js/css files. Differently if you use something like jetty you would add a folder like "webapp" containing js/css to your server context.
Anyway It works now but I wonder if is there a different maybe cleaner approach.

In AEM/CQ5 , URL redirection using /etc/map not working

I have a use case to redirect /content/project/en/test/events to /content/project/en/test page as internal redirection of page properties is not working .
I used following values under /etc/map/http folder :
sling:match as (.+)/en/test/(.+)$
sling:internalRedirect as (.+)/en/test.html
Still my required redirection is not working .
Please let me know correct configuration for the same .
Thanks&Regards.
The sling:internalRedirect is the target to which user is taken so you should use in it the match from the sling:match
use: sling:internalRedirect as $1/en/test.html
btw. there's a useful article about mappings here: https://www.cognifide.com/our-blogs/cq/multidomain-cq-mappings-and-apache-configuration/
EDIT:
a simple config like this will work (redirect from home.html to page1.html):

Decode RealUrl url in the controller

I use RealUrl for my website. In my certain extension, I require to decode the url created by RealUrl to the normal TYPO3 url format.
Example:
To my controller I get this link : typo3website/feature/number/123 , now how do I convert this to typo3website/index.php?id=99&number=123
The RealUrl does not use namespace, and hence i'm unable to understand how to create an instance of the class tx_realurl.
I tried using require_once(PATH_typo3conf.'ext/realurl'.'/class.tx_realurl.php'); and creating new instance of tx_realurl, but gives a class not found error.
If RealURL is configured properly and the link is generated with the uriBuilder or the ActionViewHelper, you don't need to take care of that. If we take your example and you configured RealURL to use typo3website/feature/number/123 for index.php?id=99&tx_yourext[number]=123, you can use this as argument for your action:
public function showAction($number) {
}
You can also access all arguments from a controller action by using
$this->request->getArguments()