-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.csx
More file actions
72 lines (59 loc) · 2.43 KB
/
function.csx
File metadata and controls
72 lines (59 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#r "Newtonsoft.Json"
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Net.Http.Headers;
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log)
{
string pageId = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
string tmplId = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "tmplid", true) == 0)
.Value;
var content = GetBlob("pages",pageId+".json");
var config = JsonConvert.DeserializeObject<Layout>(content);
string layout = "";
if(!string.IsNullOrWhiteSpace(config.layout)){
layout= GetBlob("layouts",config.layout);
log.Info(layout);
foreach(var m in config.map){
//log.Info(m.template);
log.Info("m.template");
layout = layout.Replace(m.template,m.component);
//layout = layout.Replace(m.template,"");
}
}
foreach(var m in config.map){
var manifest = GetBlob(m.component,$"1/build/asset-manifest.json");
JObject o = JObject.Parse(manifest);
layout = layout + $"<script src='https://microfrontends.azureedge.net/{m.component}/1/build/{o["main.js"]}'></script>";
}
var r = new HttpResponseMessage();
r.Content = new StringContent($"<template id='{tmplId}'>" + layout+ "</template>");
r.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
return r;
}
public static string GetBlob(string container, string file){
var connectionString ="<your connection>";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
// Create the destination blob client
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference(container);
CloudBlob blob = blobContainer.GetBlobReference(file);
// string content;
using (StreamReader reader = new StreamReader(blob.OpenRead()))
{
return reader.ReadToEnd();
}
}
public class Layout{
public string layout {get; set;}
public IEnumerable<Mapping> map { get; set;}
}
public class Mapping{
public string template {get; set;}
public string component {get; set;}
}