how to configure angular to work remotely with django APIs? - django

I am running a web application, front-end with angular and back-end with django. the thing is: These two frameworks are not running on the same server. how can I configure angular to work remotely with APIs? (I have tested the APIs, and they are just fine)

Check setup proxy for your project from Proxying to a backend server
Basically you need to create a proxy.conf.json file and have settings like:
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}
Then you can define your backend hostname, port and available APIs and other settings.

OK, after hours of debugging I finally found it.
FIRST Create a file named proxy.conf.json in /src folder and fill it with this json:
{
"/api": {
"target": "http://test.com/",
"secure": false,
"changeOrigin": true,
"logLevel": "info"
}
}
This line is ESSENTIAL:
"changeOrigin": true,
THEN Edit the angular.json file.In the projects section, find architect and append this line to optionssection:"proxyConfig":"src/proxy.conf.json". So it should look like this:
.
.
.
"options": {
"browserTarget": "some-name:build",
"proxyConfig": "src/proxy.conf.json"
},
.
.
.
NOTE1 Trailing comma is not allowed in JSON.
NOTE2 Loglevel gives you more information.
NOTE3 Thanks to Haifeng for his guide.

Related

Create a Sharepoint list in a specific folder with Microsoft graph api

Premise:
I have a folder under the sharepoint site for e.g.
https://... <mycompany-sharepoint-site.com>/
under which we have folder so my url is something like
https://... <mycompany-sharepoint-site.com>/Documents/Sub_folder_1/Sub_folder_2
pertaining to our project.
I need to be able to create a Sharepoint list in the Sub_folder_2 - folder and not at the root level.
With Sharepoint - GraphApi - create list api url
POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists
I will ONLY be able to create at the <mycompany-sharepoint-site.com> level (i.e. at the root level) which is not what I want.
FYI, I already tried (on Postman) to go with the drives//items/<folder_id> - route or I should say attempted to do so but failed.
Any help is greatly appreciated.
If you want to use Graph API to create a folder in SharePoint, please use the following query:
POST /groups/{group-id}/drive/items/{parent-item-id}/children
For more information: https://learn.microsoft.com/en-us/graph/api/driveitem-post-children?view=graph-rest-1.0&tabs=http#http-request
Hope this is helpful.
I don't think that SharePoint supports creating a list inside the folder but you can at least try to create a list and specify the path in the parent reference.
You need to find out the drive id.
POST https://graph.microsoft.com/v1.0/sites/{site_id}/lists
{
"displayName": "Test",
"columns": [
{
"name": "Column1",
"text": {}
},
{
"name": "Column2",
"number": {}
}
],
"list": {
"template": "genericList"
},
"parentReference": {
"driveType": "documentLibrary",
"driveId": "{drive_id}",
"path": "/drives/{drive_id}/root:/Documents/Sub_folder_1/Sub_folder_2"
# or
# "path": "/drives/{drive_id}/root:/Sub_folder_1/Sub_folder_2"
}
}
I don't think it's even possible at all, did you succeed that manually?

Get proper usernames to populate on Superset with Azure SSO instead of ID string

I've finally gotten Azure Single Sign-On (SSO) connected to Apache Superset running via docker-compose, following the Flask docs. Users in my company's Azure group can create and access Superset accounts by logging in with Azure and they are assigned roles based on their identity. This is good.
The usernames they get assigned, however, are long Azure ID strings. These are undesirable in displays. Here's what my account looks like on the List Users screen and on my profile:
How can I modify either my Azure application SSO setup or my Superset config to have Superset populate usernames like SFirke for the account usernames, instead of values like 3ee660ff-a274 ... ?
The security part of my config.py looks like this, almost identical to the Flask template:
OAUTH_PROVIDERS = [
{
"name": "azure",
"icon": "fa-windows",
"token_key": "access_token",
"remote_app": {
"client_id": "CLIENT_ID",
"client_secret": "CLIENT_SECRET",
"api_base_url": "https://login.microsoftonline.com/TENANT_ID/oauth2",
"client_kwargs": {
"scope": "User.read name preferred_username email profile upn groups",
"resource": "RESOURCE_ID",
},
"request_token_url": None,
"access_token_url": "https://login.microsoftonline.com/TENANT_ID/oauth2/token",
"authorize_url": "https://login.microsoftonline.com/TENANT_ID/oauth2/authorize",
},
},
]
EDIT: Looks like the way to go is writing a custom userinfo retrieval method, there's a template on the Flask page linked above and an example used for Superset in this Github comment. I think I would use a line like "id": me["preferred_username"] or "id": me["upn"], based on the field names in the Microsoft docs.
But Microsoft notes that this value can change over time and should not be used for authorization changes. Since the oid value is immutable, and it is hardly visible to the typical user, I plan to just stick to it.

django-redis persisting json data

I have a small django site which controls an anstronomy dome and house automation. On start up the project loads 3 json files: relays, conditions and homeautomation. To avoid constant reading and writing to the Pi4's ssd I load the json files into REDIS (on start up in apps, see below). I already have REDIS running in a docker as the project uses celery.
My problem is that within a few minutes of loading the json into REDIS it clears the data out of cache.
I load the json file in the form of a dictionary (dict) in apps
cache.set("REDIS_ashtreeautomation_dict", dict, timeout=None)
and set
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://redis:6379",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"SERIALIZER": "django_redis.serializers.json.JSONSerializer",
"TIMEOUT": None
}
}
}
I don't need the data to persist if the dockers go down and I don't need db functions. Caching these files is ideal but I need them to 'stay alive' for the lifetime of the server.
Thank you.
Thank you Kevin.
Moving TIMEOUT solved the issue.
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://redis:6379",
"TIMEOUT": None,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"SERIALIZER": "django_redis.serializers.json.JSONSerializer",
}
}
}
I am going to include some code to catch the long term REDIS 'eviction' policies (i.e. reload the json data). I don't want to delve into the REDIS docker.
Thanks
Ian

How can I play a WebRTC livestream from flutter?

my use case is a webrtc livestream is coming from AWS Kinesis, that I want to play in flutter app. I am new to WebRTC and AWS. And for flutter_webrtc lib, there is no proper documentation available.
Here is my sample response which comes from live video API (hiding few details in response):
{
"status": true,
"data": {
"shadowState": "Device Shadow updated successful!",
"channelARN": "arn:aws:kinesisvideo:us-west-2:",
"region": "us-west-2",
"clientId": "clientId",
"signalingChannelEndpoint": "wss://v-123.kinesisvideo.us-west-2.amazonaws.com",
"signedEndpointUrl": "wss://v-123.kinesisvideo.us-west-2.amazonaws.com/?...&X-Amz-SignedHeaders=host",
"iceServers": [
{
"urls": "stun:stun.kinesisvideo.us-west-2.amazonaws.com:443"
},
{
"urls": [
"turn:12-34-567-890.t-123.kinesisvideo.us-west-2.amazonaws.com:443?transport=udp",
"turns:12-34-567-890.t-123.kinesisvideo.us-west-2.amazonaws.com:443?transport=udp",
"turns:12-34-567-890.t-123.kinesisvideo.us-west-2.amazonaws.com:443?transport=tcp"
],
"username": "1....2:djE....UxODc1",
"credential": "2eg..NOc/1c..."
}
]
}
}
And there is no official lib from AWS for this, so I tried to use this lib aws_kinesis_video_signaling_api but again no proper documentation is there. Anyone please help me understand these things. Thank you
The flutter_webrtc takes in a configuration map something similar to the one mentioned.
Map<String, dynamic> configuration = {
"iceServers": [
{"url": "stun:stun.l.google.com:19302"},
]
};
You can add some offerSdpConstraints and pass this configuration to
RTCPeerConnection pc =
await createPeerConnection(configuration, offerSdpConstraints);
to connect to a remote peer. The documentation isn't very helpful but if you're looking for a guide on Flutter x WebRTC, I've written an article on Flutter and WebRTC integration on the 100ms blog.

Make ng serve on Angular 12 loads environment.ts instead of environment.prod.ts?

I read that Angular 12 changed some default configurations.
Now I'm not able to load environment.ts when starting the app with ng serve; environment.prod.ts is called instead.
I tried to load environment.ts typing ng serve --configuration=development, but environment.prod.ts is called again.
I edited the development property of angular.json this way, by adding the fileReplacements property and it works, but this seems a workaround to me and not the right solution:
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true,
"fileReplacements": [
{
"replace": "src/environments/environment.prod.ts",
"with": "src/environments/environment.ts"
}
]
}
Is there a better solution to start a development environment when running ng serve?