diff --git a/.vscode/launch.json b/.vscode/launch.json index 5e96a3e..cad597c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/api/bin/Debug/netcoreapp2.2/api.dll", + "program": "${workspaceFolder}/api/bin/Debug/netcoreapp2.2/Dta.Frontdoor.Api.dll", "args": [], "envFile": "${workspaceFolder}/config/local.env", "cwd": "", diff --git a/api/Controllers/BotConnectorController.cs b/api/Controllers/BotConnectorController.cs index 00660eb..cf75760 100644 --- a/api/Controllers/BotConnectorController.cs +++ b/api/Controllers/BotConnectorController.cs @@ -18,15 +18,16 @@ public BotConnectorController(IConfiguration configuration) _configuration = configuration; } - // GET api/values/5 [HttpGet] - public async Task> Get(int id) + public async Task Get() { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("Authorization", $"BotConnector {_configuration["botConnector"]}"); var response = await client.GetStringAsync("https://webchat.botframework.com/api/tokens"); - return response; + return new { + token = response.Trim('"') + }; } } } diff --git a/api/Startup.cs b/api/Startup.cs index c1a025f..68299a7 100644 --- a/api/Startup.cs +++ b/api/Startup.cs @@ -19,12 +19,19 @@ public Startup(IConfiguration configuration) { Configuration = configuration; } - + private readonly string _devOrigins = "_devOrigins"; public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.AddCors(options => { + options.AddPolicy(_devOrigins, builder => { + builder.WithOrigins("http://localhost:3000") + .AllowAnyHeader() + .AllowAnyMethod(); + }); + }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddOptions(); @@ -44,7 +51,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } - + app.UseCors(_devOrigins); app.UseHttpsRedirection(); app.UseMvc(); } diff --git a/ui/package-lock.json b/ui/package-lock.json index b157996..55bc84d 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -1660,12 +1660,11 @@ } }, "@types/vfile-message": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@types/vfile-message/-/vfile-message-1.0.1.tgz", - "integrity": "sha512-mlGER3Aqmq7bqR1tTTIVHq8KSAFFRyGbrxuM8C/H82g6k7r2fS+IMEkIu3D7JHzG10NvPdR8DNx0jr0pwpp4dA==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/vfile-message/-/vfile-message-2.0.0.tgz", + "integrity": "sha512-GpTIuDpb9u4zIO165fUy9+fXcULdD8HFRNli04GehoMVbeNq7D6OBnqSmg3lxZnC+UvgUhEWKxdKiwYUkGltIw==", "requires": { - "@types/node": "*", - "@types/unist": "*" + "vfile-message": "*" } }, "@types/yargs": { @@ -2333,6 +2332,43 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" }, + "axios": { + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz", + "integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==", + "requires": { + "follow-redirects": "1.5.10", + "is-buffer": "^2.0.2" + }, + "dependencies": { + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + } + }, + "is-buffer": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", + "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, "axobject-query": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.0.2.tgz", @@ -14636,9 +14672,12 @@ } }, "unist-util-stringify-position": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-1.1.2.tgz", - "integrity": "sha512-pNCVrk64LZv1kElr0N1wPiHEUoXNVFERp+mlTg/s9R5Lwg87f9bM/3sQB99w+N9D/qnM9ar3+AKDBwo/gm/iQQ==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-2.0.1.tgz", + "integrity": "sha512-Zqlf6+FRI39Bah8Q6ZnNGrEHUhwJOkHde2MHVk96lLyftfJJckaPslKgzhVcviXj8KcE9UJM9F+a4JEiBUTYgA==", + "requires": { + "@types/unist": "^2.0.2" + } }, "unist-util-visit": { "version": "1.4.1", @@ -14884,6 +14923,19 @@ "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==" + }, + "unist-util-stringify-position": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-1.1.2.tgz", + "integrity": "sha512-pNCVrk64LZv1kElr0N1wPiHEUoXNVFERp+mlTg/s9R5Lwg87f9bM/3sQB99w+N9D/qnM9ar3+AKDBwo/gm/iQQ==" + }, + "vfile-message": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-1.1.1.tgz", + "integrity": "sha512-1WmsopSGhWt5laNir+633LszXvZ+Z/lxveBf6yhGsqnQIhlhzooZae7zV6YVM1Sdkw68dtAW3ow0pOdPANugvA==", + "requires": { + "unist-util-stringify-position": "^1.1.1" + } } } }, @@ -14893,11 +14945,12 @@ "integrity": "sha512-Pa1ey0OzYBkLPxPZI3d9E+S4BmvfVwNAAXrrqGbwTVXWaX2p9kM1zZ+n35UtVM06shmWKH4RPRN8KI80qE3wNQ==" }, "vfile-message": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-1.1.1.tgz", - "integrity": "sha512-1WmsopSGhWt5laNir+633LszXvZ+Z/lxveBf6yhGsqnQIhlhzooZae7zV6YVM1Sdkw68dtAW3ow0pOdPANugvA==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-2.0.1.tgz", + "integrity": "sha512-KtasSV+uVU7RWhUn4Lw+wW1Zl/nW8JWx7JCPps10Y9JRRIDeDXf8wfBLoOSsJLyo27DqMyAi54C6Jf/d6Kr2Bw==", "requires": { - "unist-util-stringify-position": "^1.1.1" + "@types/unist": "^2.0.2", + "unist-util-stringify-position": "^2.0.0" } }, "vm-browserify": { diff --git a/ui/package.json b/ui/package.json index 6853a8f..0cabe3d 100644 --- a/ui/package.json +++ b/ui/package.json @@ -8,6 +8,7 @@ "@gov.au/grid-12": "^2.1.0", "@gov.au/header": "^4.1.12", "@gov.au/main-nav": "^1.0.8", + "axios": "^0.19.0", "botframework-webchat": "^4.6.0", "express": "^4.17.1", "node-sass": "^4.13.0", @@ -33,6 +34,7 @@ "lint": "tslint --config ./tslint.json --project ./", "lint:fix": "tslint --project ./ --fix" }, + "proxy": "http://localhost:5000", "eslintConfig": { "extends": "react-app" }, diff --git a/ui/src/pages/buyer/BuyerPage.tsx b/ui/src/pages/buyer/BuyerPage.tsx index a6c55ae..c46eaa0 100644 --- a/ui/src/pages/buyer/BuyerPage.tsx +++ b/ui/src/pages/buyer/BuyerPage.tsx @@ -1,10 +1,26 @@ -import React from 'react'; +import axios from 'axios'; +import { DirectLine } from 'botframework-directlinejs'; +import ReactWebChat from 'botframework-webchat'; +import React, { useEffect, useRef, useState } from 'react'; import '../../main.scss'; const BuyerPage: React.FC = () => { + const [loaded, setLoaded] = useState(false); + const directLine = useRef(null); + useEffect(() => { + if (!loaded) { + axios.get('/api/BotConnector') + .then((r) => { + directLine.current = new DirectLine({ token: r.data.token }); + setLoaded(true); + }); + } + }); + return (
{'Buying digital products & services'} + {loaded && }
); };