Is there an equivalent in Giraffe to Url.Content("~/")? - asp.net-mvc

In ASP.NET MVC, I used occasional calls such as Url.Content("~/Some folder/") to get the full path of different URLs.
Is there anything similar in Giraffe?
The following code comes from the default app I created with the template:
let layout (content: XmlNode list) =
html [] [
head [] [
title [] [ encodedText "TestAccountsManager" ]
link [ _rel "stylesheet"
_type "text/css"
_href "/main.css" ]
]
body [] content
]
Is /main.css relative to the root of the application? Or is it relative to the server name? In ASP.NET MVC, I would use something like ~/css/main.css, let's say. If the app is deployed under http://example/someapp/ or http://example/ I know this would work in both cases.

In the case of the default Giraffe template, where static resources get put in the WebRoot folder, it seems to work if you use:
_href "./main.css"
This allows for deploying the web application at the root of the host, or as a "folder" one level below the root.
If you are putting the static resources in a folder below the WebRoot, then resources would go in the folder:
WebRoot\Subfolder
(e.g. WebRoot\css), and the href attribute would need to be changed to:
_href "./Subfolder/main.css
(e.g. _href "./css/main.css")

Related

Add Swagger base path field in Nest.js project

I am trying to use nestjs/swagger to create a swagger file from my back-end and I am facing a problem related to the base path. What I want to achieve is to show version as base path instead of showing it in all the methods available, which is ugly and confusing.
My API, right now, has the following structure (this is a set of what is present in app.module.ts):
const routes: Routes = [
{
path: '/api',
module: ApiModule,
children: [
{
path: '/v1',
module: V1Module,
children: [
{
path: '/orders',
module: OrdersModule
},
{
path: '/users',
module: UsersModule
}
]
}
]
}
];
This way, once I generate and check the swagger, I see all my methods following the /api/v1 prefix. This could be an example:
orders
GET /api/v1/orders
POST /api/v1/orders
GET /api/v1/orders/{order_id}
...
users
GET /api/v1/users
POST /api/v1/users
GET /api/v1/users/{user_id}
...
What I want is to get rid of /api/v1 appearing in any method. I know that SWAGGER has fields for host and basePath, but do not find any way to populate it in Nest.js. Researching, I have found that there were .setBasePath() and .addServer() methods, but they do not work for me (I am pretty sure they are deprecated).
Thank very much for your help.
If you want nestjs to add api/v1 to every endpoint then use setGlobalPrefix('api/v1') to do that.
https://docs.nestjs.com/faq/global-prefix#global-prefix

PWA Service Worker (Workbox) setting's '/' stand for?

I want to create PWA's service worker file by using workbox.
According to workbox document, precaching setting of workbox is something like this:
service-worker.js
workbox.precaching.precacheAndRoute([
'/styles/example.ac29.css',
{ url: '/index.html', revision: 'abcd1234' },
// ... other entries ...
]);
But what is the actual meaning of /index.html or /styles/example.ac29.css?
It is server root? or, the root of PWA's scope?
For example, if service-worker.js is served in https://example.com/hoge/fuga/service-worker.js, and manifest.json is also served in https://example.com/hoge/fuga/manifest.json with content:
{
"name": "Great PWA site",
"background_color": "#f6f0d3",
"icons": [...],
"start_url": "https://example.com/hoge/fuga/",
"scope":"/hoge/fuga/",
"display": "standalone"
}
In such case, /index.html in workbox setting means https://example.com/index.html? Or, https://example.com/hoge/fuga/index.html?
Within Workbox's precache manifest, /index.html is resolved to a full URL using the server root as the base. It does not user the service worker scope as the base. (After Googling, I guess it's technically called a "root-relative" URL, though I've never really used that phrase before.)
If you had a relative URL like ./index.html, it would be resolved to a full URL using the location of the service worker script as the base.
In general, if you're curious as to what a URL will resolve to, you can run the following from the ServiceWorkerGlobalScope to see:
(new URL('some-URL.html', self.location.href)).href
The easiest way to do this is to open up Chrome's DevTools while on a page you're curious about that has a service worker, go to the Console panel, and choose the service worker's scope in the popup menu, and then enter the code above.

Vue.js, Url and Routing

I'm writing a Vue.js application. I don't know why it keeps appending '#' to every Url I type into the browser. Has anyone had a similar issue with Vue? For example, when I type 'localhost:8080/register' the browser changes it into 'localhost:8080/register#/'. The routing isn't working properly either. Does anyone know what may be causing the problem?
In your route configuration, set the mode to history.
mode: "history"
like:
const router = new VueRouter({
mode: "history",
routes: [
// ...
]
})

django rest framework display ViewSet and classic endpoints for all app in api root

Is there a way to display ViewSet endpoints (generated by router) AND classic endpoint (defined in the urls.py in each app) all in the api root together ?
app1 url.py:
router = DefaultRouter()
router.register(r'^foo', views.FooViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
url('bar/', views.BarListView.as_view(), name='bar-list'),
url('baz/', views.BazListView.as_view(), name='baz-list'),
]
app2 url.py:
router = DefaultRouter()
router.register(r'^qux', views.QuxFooViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
url('quux/', views.QuuxListView.as_view(), name='quux-list'),
url('corge/', views.CorgeListView.as_view(), name='corge-list'),
]
global url.py:
urlpatterns = [
url(r'^', include('app1.urls')),
url(r'^', include('app2.urls')),
]
API-root:
HTTP 200 OK
Allow: GET, OPTIONS
Content-Type: application/json
Vary: Accept
{
"foo": "http://localhost:8000/foo/",
"bar": "http://localhost:8000/bar/"
"baz": "http://localhost:8000/baz/"
"qux": "http://localhost:8000/qux/"
"quux": "http://localhost:8000/quux/"
"corge": "http://localhost:8000/corge/"
}
This is the result I would like to get. But at the moment I can only display either router urls or classic urls but not both. And when I try to diplay more than one router, it only display the first one (as explained in django's doc). Is there a way to do that ?
No, but you can still use model or non model viewset instead of the APIView.
from rest_framework import viewsets
class BarListView(viewsets.ViewSetMixin, <what you already had>):
<your current code>
and that should do.
Note that if it's a non model view, you'll need to add base_name to the router's registration.

How to show the auth page if the URL doesn't contain extra path?

I use Spring security plugin for our Grails application.
How to show the authentication page if the user typed the URL without any extra path, for example:
http://localhost:8080/OurGrails
I use Config.groovy file to specify URL constraints:
grails.plugins.springsecurity.interceptUrlMap = [
'/zoning/*': ['ROLE_USER'],
'/**': ['IS_AUTHENTICATED_ANONYMOUSLY']
]
That would be '/': ['ROLE_USER'] and in some containers might also require '/index.gsp': ['ROLE_USER'].

Resources