How to read the apple-app-site-association file on Vapor 4? - content-type

For the auto-fill password to work on the Apple platforms, I am testing out Apple App Site Association (AASA) Validator in this website.
I have added the required json in the Public/.well-known/apple-app-site-association file for the auto-fill password to work on my iOS application.
The result from this test comes back with this error:
Your file's 'content-type' header was not found or was not recognized.
Does anyone have ever encounter this issue? It seems that the AASA file is not being downloading into my device.
Note that on iOS 14, AASA files will be delivered via Apple's CDN, which is different from how AASA files are currently downloaded.
Is there something else to do about it on my Vapor 4 project to make things work?

I meat the same issue, follow by imike's answer and doing some research, here is the solution.
create a custom Middleware
struct UniversalLinksMiddleware: Middleware {
func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
guard request.url.string == "/.well-known/apple-app-site-association" else {
return next.respond(to: request)
}
return next.respond(to: request).map { response in
response.headers.add(name: "content-type", value: "application/json")
return response
}
}
}
add this middleware at config.swift file. Be aware of the order you add middleware, you must add it before FileMIddleware. Because the responses leaving your application goes through the middleware in reverse order.
app.middleware.use(UniversalLinksMiddleware())
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))

Related

Next.JS - localhost is prepended when making external API call

I got a simple Next app where I'm making an external API call to fetch some data. This worked perfectly fine until a couple days ago - when the app is making an API request, I can see in the network tab that the URL that it's trying to call, got Next app's address (localhost:3000) prepended in front of the actual URL that needs to be called e.g.: instead of http://{serverAddress}/api/articles it is calling http://localhost:3000/{serverAddress}/api/articles and this request resolves into 404 Not Found.
To make the API call, I'm using fetch. Before making the request, I've logged the URL that was passed into fetch and it was correct URL that I need. I also confirmed my API is working as expected by making the request to the expected URL using Postman.
I haven't tried using other library like axios to make this request because simply it doesn't make sense considering my app was working perfectly fine only using fetch so I want to understand why is this happening for my future experience.
I haven't made any code changes since my app was working, however, I was Dockerizing my services so I installed Docker and WSL2 with Ubuntu. I was deploying those containers on another machine, now both, the API I'm calling and Next app are running on my development machine directly when this issue is happening.
I saw this post, I confirmed I don't have any whitespaces in the URL, however, as one comment mentions, I installed WSL2, however, I am not running the app via WSL terminal. Also, I've tried executing wsl --shutdown to see if that helps, unfortunately the issue still persists. If this is the cause of the issue, how can I fix it? Uninstall WSL2? If not, what might be another possible cause for the issue?
Thanks in advance.
EDIT:
The code I'm using to call fetch:
fetcher.js
export const fetcher = (path, options) =>
fetch(`${process.env.NEXT_PUBLIC_API_URL}${path}`, options)
.then(res => res.json());
useArticles.js
import { useSWRInfinite } from 'swr';
import { fetcher } from '../../utils/fetcher';
const getKey = (pageIndex, previousPageData, pageSize) => {
if (previousPageData && !previousPageData.length) return null;
return `/api/articles?page=${pageIndex}&limit=${pageSize}`;
};
export default function useArticles(pageSize) {
const { data, error, isValidating, size, setSize } = useSWRInfinite(
(pageIndex, previousPageData) =>
getKey(pageIndex, previousPageData, pageSize),
fetcher
);
return {
data,
error,
isValidating,
size,
setSize
};
}
You might be missing protocol (http/https) in your API call. Fetch by default calls the host server URL unless you provide the protocol name.
Either put it into env variable:
NEXT_PUBLIC_API_URL=http://server_address
Or prefix your fetch call with the protocol name:
fetch(`http://${process.env.NEXT_PUBLIC_API_URL}${path}`, options)

Autodesk forge Webhook API, Error 400 400, VALIDATION_ERROR

using autodesk forge API, I am trying to create a webhook over folder using the following information; unfortunately, I am receiving the following response:
{
"id":"xxxx-xxxx-xxx-xxxxx",
"status":400,
"code":"VALIDATION_ERROR",
"detail":["Payload is not valid for serialization"]
}
URL:
https://developer.api.autodesk.com/webhooks/v1/systems/data/events/dm.folder.added/hooks (for specific folder added event) or: https://developer.api.autodesk.com/webhooks/v1/systems/data/hooks (for all events). Both are returning the same error
Header:
{
"Content-Type":"application/json",
"Authorization":"<MY_TOKEN>",
"x-ads-region":"US"
}
Data:
{
"callbackUrl":"<MY_DOMAIN>:<MY_PORT>/callback",
"scope":{
"folder":"urn:adsk.wipprod:fs.folder:co.xxxxxxxxxxxx-xxxxx"
}
}
Troubleshooting:
I've tried different folders, root and non-root. I can access all the folders i tried using the api
I am sure that my account is US region
I've tried to add hubId and/or projectId, but I received the same error
<MY_DOMAIN>:<MY_PORT>/callback is configured and working fine
Headers and Data are serializing and de-serializing normally using json loads & dumps
Any suggestion/help?
Answering myself :)
I've discovered that my issue is not related to Forge API, it's a general one related to python Requests. The payload (data) of Requests cannot be nested dictionary, only 1 level dictionary is accepted, nested ones will fail. the solution is to stringify the dict (json.dumps) and use that string as request payload.

Enable CORs for Swashbuckle swagger.json in .NET Lambda API

I have a .NET lambda API that I was previously using Swashbuckle to generate a swagger.json file that was given to an external site to use. I am now trying to setup so the swagger.json file is is generated by the API and available through a url for the external site to us ie: mylambdaapi.com/swagger/v2/swagger.json. I was able to get this working by adding a dummy event to my template when pushing to aws as follows.
"SwaggerJson": {
"Type": "Api",
"Properties": {
"Path": "/swagger/v2/swagger.json",
"Method": "GET"
}
}
This works for just accessing the file normally, however the external site will run into CORS "No 'Access-Control-Allow-Origin' header" issues when trying to load the json. Is there any way to force the generation to use "Access-Control-Allow-Origin" in this case? Or is this not feasible in this way? I'm working off what another developer had built previously so I'm trying not to rewrite every, however I'm open to another method as long as it is able to produce some swagger json that the external site can consume.
EDIT: I should note that I am using API gateway, hover the swagger.json is only used for documentation purposes for the external site.
Attempted to use UseCors() functionality however that did not work. I was able to fix the issue by adding an anonymous function to handle the response before UseSwagger.
The following snip-it is from the Configure function in my startup.
app.Use((context, next) =>
{
context.Response.Headers["Access-Control-Allow-Origin"] = "*";
return next.Invoke();
});
app.UseSwagger();

Nuxt SSR blog still calling API endpoints to get blog posts even thought its setup to be SSR

been playing around with a simple blog built with JSONPlaceholder and Nuxt.js
Everything seems fine, I've got an archive and single blog posts working fine but when deployed on Netlify I can see that the browser is still doing API calls to JSONPlaceholder even though all the pages are built static and I can see they already have the content within the HTML.
I used the routes method within generate in the nuxt config to create the 100 html files based upon the JSONPlaceholder /posts results.
Here's the Netlify link: REMOVED.
And a public repo: https://bitbucket.org/oneupstudio/api-test/src/master/
Anything I've missed?
Nuxt.js doesn't support 'full static generation' yet, check this RFC.
For now, you can use this module in order to make your JSON requests static.
Nuxt currenty supports proper static generation of websites. Although one has to be aware of payload param in asyncData. So if payload is present that indicates that static generator is at work and no api calls should be made in this case:
async asyncData ({ params, error, payload }) {
if (payload) return { user: payload }
else return { user: await backend.fetchUser(params.id) }
}
Read more on this here.
RFC mentioned by #DreadMinder will further improve on this, but you can already do full static websites with Nuxt.

Angular 2 always returns http status code 200 on this.http.get() even if the file doesn't exist

i'm trying to check if a pdf file exists on the server with an HTTP get request,for that i am testing if the status code returned by the server's response is different then 200, the problem is that i always get status code 200 and statusText "OK".
here's my Service class
getPdf(year: number,type: number, num: number): boolean{
this.http.get('http://localhost:4200/app/pdfs/'+year+'/'+type+'/'+num+'.pdf')
.subscribe(data => console.log(data));
return true;
}
in my component i have this code :
ngOnInit(){
this.pdfService.getPdf(2016,71015,1275);
}
and that's the result i get in Chrome dev tools console
any ideas of why that is happening and how i can check the existance of a file if this method is not applicable?
I think your server is redirecting some or all requests for assets not found to your main page. It is somewhat common for a single page app. You need to update your server configurations to make it return a not found response for some folders at least.

Resources