How to handle dynamic list (JSON) of redirects on NextJS + AWS Amplify? - redirect

I have a JSON file with 8k+ redirects that I use for my site. This JSON is hosted on a CDN (AWS Cloudfront). And every time one of our products or pages change their path, that JSON is automatically updated with a new redirect, and this happens pretty often (more than once a day).
I want to be able to use that JSON on my NextJS (12.3) project hosted on AWS Amplify.
Ideally I wanted to use the NextJS middleware.js to fetch that JSON and redirect to the proper path.
But right now Amplify doesn't support that middleware. They still have an open issue on github for that:
https://github.com/aws-amplify/amplify-js/issues/9145
So I tried to run that on getServerSideProps. But I'd have to replicate that for every URL segment on my project, which wouldn't look great.
Right now I use the native redirects solution on the next.config.js file (https://nextjs.org/docs/api-reference/next.config.js/redirects).
But this solution isn't great either for two reasons:
This is not dynamic. The JSON file is only fetched when the project is build up, so many times I have to redeploy my project on Amplify to be able to update those redirects.
The latency to find the correct path is affecting the page load perfomance (it takes around 400 to 500ms to run through the 8k+ redirects).
Can anyone help me to find a fast and dynamic solution to fetch and do those redirects on NextJS? Or maybe any idea to do that in a different way.

Related

SystemJS Cache - Generate timestamp

I am using Single SPA + SystemJS.
The problem I am having is that my entry assets are being cached by the browser.
Joel Denning said
Browser-only solution
Add a query string with the current timestamp to the URL. For example, download ./entry.js?t=1573878549105
Joel Denning's post
I am thinking of a way to do this in the EJS file. Because if I generate this on the code, it will be evaluated at build time, but I need something on the browser side.

SAPUI5 load file in the workspace

I need to upload files in the Workspace:
I dont know which URL i should give as parameter to my file Uploader. Considering that i working with the SAP WebIDE personal Edition and my file are located in the following path:
file:///C:/SAPWebIDE/eclipse/serverworkspace/Al/ALine/OrionContent/testApp/webapp/model/
What should i please set as Url here?
var oFileUploader2 = new sap.ui.commons.FileUploader({
name: "upload2",
uploadOnChange: false,
uploadUrl: "???"
});
I think you have misunderstood how the FileUploader works.
The "uploadUrl" parameter should be used to specify a path on the "web server" (e.g. application server, web container) on which your application is hosted. UI5 is a web user interface framework, it does not know how to handle (server-side) upload requests. This means that the server (backend) itself should have some implementation for handing the file upload.
After you select the file and trigger the upload, a POST HTTP request is made to the path specified in this "uploadUrl" parameter. If you have no web server to know to handle it, then it will invariably give back an error HTTP response.
Based on the title of your question, I understand that you would want to upload the file inside your workspace. IMO, this does not really make sense (as you are mixing in the design time environment with your run-time environment (i.e. your application should never depend on the IDE).
Nevertheless, you can try and import a file via the import menu (right click on package, import, from file system) and see what URL is the request triggered against (using the dev console). I looked around a little and roughly this is the request URL: http://localhost:[Web IDE Port]/xfer/import/[User Name]-OrionContent/[Project Name]. In the Slug header you would have the file name. You might not be able to make a POST request towards this URL directly (because of XSS / CSS limitations), so you might need to create a route mapping for it.

Visual studio unable to add swagger metadata file in my rest api client

I am new to mobile development. As i am familiar with c# .net so i am using xamarin plugin for visual studio. I have created a sample app in which i have used SQLite, created a DB and then performed CRUD operations. At this point all things are working good. But i already have a local DB and i want to use it. For this i have made an offline Azure api using swagger and on Release i have saved the files locally by using File System in release option in VS. Now i want to add my app as rest api client and want to use my local DB. But when i try to add as rest api client and then i select select an existing swagger file so while browsing i can't find any file. For reference please see the images bellow
So when i click browse and goto the location where i have saved my files for swagger i get nothing as shown in bellow image
Also it's finding the .json extension file which is not present in my publish api.
I don't know why it's happening, also as already told above i am new to mobile development i am not sure what to do. Kindly see the bellow image of my swagger UI
Any help would be highly appreciated
The URL you listed is for the user-friendly reference docs for your API; there should be a corresponding URL for the JSON definition endpoint for your API. Use this instead in the Add Rest API Client dialog in the "Swagger URL" option.
The other option is to use this peer URL to download the JSON description of your REST API into a local .json file and reference that when generating your client access classes.
For an example of these two endpoints, see https://msdn.microsoft.com/en-us/library/mt788315.aspx#Anchor_1.
Why you are using azure? I guess your are working in a company so they must have a server. Just publish your services on the server and then sync it with your mobile app and DB. This is the easiest and free way to do it. You can use Rest services for that

Maintaining (version + redirect) in S3

So, far in our application, the *.js files were served directly from apache. For example, this was a script include in a jsp page : /foo/v6565/my_script.js. The v6565 in the path is phony and an internal apache redirect, redirects /foo/v6565/my_script.js to /foo/my_script.js.
Whenever my_script.js is updated, v<xxxx> in the included jsp page (an internal tool does it based on the SVN revision of my_script) is updated - thus forcing the browser to fetch my_script.js again and not the cached version. I hope I am able to explain my current approach clearly.
[A different approach could have been to user /foo/my_script.js?v=5652. However, there was some caching issue (can't remember it) because of which the decision was taken to use /foo/v56564/ instead of adding version to the queryParam. I will dig into it, though]
Now, that we are moving all of our *.js files to an s3 bucket, I was wondering what would be a way of doing this?
The path from s3 bucket would look like : mybucket.aws.com/js/my_script.js. How to I insert the version tag + redirection for s3? Are there any other standard approaches used when resources are served from s3?
(I've read about page redirects on s3 resources but the redirects are to be written directly on the resources, which is not really applicable in my case)
Thanks.
I think cache busting with ?v=<hash> is pretty much standard now.
It has been disadvised, however that's a pretty old resource (though often cited) and I'm not sure if this is still true. Even your trusted StackOverflow is using it with SHA1, so I guess it's good enough for everybody now.

Which is the best method to get a local file URI and save it online?

I'm working on a web project but the scenario has some restrictions for a specific user case. We have been investigating a web-only solution and a dropbox-like native way to solve this.
The main restriction is that we shouldn't upload local files to a cloud. We can only track local URI's.
The use cases are:
As a developer, I should be able to link the URI of a local file to a webapp. Thus, I can click on a webapp element and the local file should be opened.
As a user, I should be able to add a directory and view the same structure on the webapp (clicking opens the file). The files are not uploaded.
Possible solutions:
We started trying the FileSystem API but when the specs. were fully defined, we figured out that a local sandbox was not enough, and we can't access to the local URI due to security issues.
We are considering a Dropbox-like native app. The Invision Sync App is closer to what we want.
The less optimal solution would be a complete native application.
The question:
Which is the more efficient way to achieve this? Any idea on some native libraries for doing this faster? Any web-only workaround?
Thanks in advance.