docs: fix proxy setting

This commit is contained in:
Jan De Dobbeleer 2022-01-09 13:53:14 +01:00
parent e9910c4a3e
commit bd299c924e
No known key found for this signature in database
GPG key ID: F6CC273CE5BA9AEE
3 changed files with 11 additions and 5 deletions

View file

@ -6,10 +6,12 @@ module.exports = async function (context, req) {
// https://www.strava.com/oauth/authorize?client_id=76033&response_type=code&redirect_uri=https://ohmyposh.dev/api/auth&approval_prompt=force&scope=read,activity:read&state=strava
try {
const code = (req.query._code || (req.body && req.body.code));
const code = (req.query.code || req.query._code || (req.body && req.body.code));
const segment = (req.query.state || (req.body && req.body.state));
if (!code || !segment) {
context.log(`Issue processing request: missing code (${code}) or segment (${segment})`);
context.res = {
body: "not all query parameters are set",
status: 400
};
return;
@ -21,6 +23,7 @@ module.exports = async function (context, req) {
body = await strava.getStravaToken(code);
break;
default:
context.log(`Unknown segment: ${segment}`);
context.res = {
body: "unknown segment",
status: 400
@ -28,7 +31,7 @@ module.exports = async function (context, req) {
return;
}
const url = `https://ohmyposh.dev/docs/auth?segment=${segment}&access_token=${body.access_token}&refresh_token=${body.refresh_token}`;
const url = `${process.env['DOCS_LOCATION']}/docs/auth?segment=${segment}&access_token=${body.access_token}&refresh_token=${body.refresh_token}`;
const res = {
status: 302,
@ -39,7 +42,7 @@ module.exports = async function (context, req) {
};
context.done(null, res);
} catch (error) {
context.log(error);
context.log(`Issue processing request:\n${error}`);
context.res = {
body: error,
status: 500

View file

@ -2,6 +2,8 @@
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "node"
"FUNCTIONS_WORKER_RUNTIME": "node",
"API_LOCATION": "http://localhost:7071",
"DOCS_LOCATION": "http://localhost:3000"
}
}

View file

@ -2,11 +2,12 @@
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"callback": {
"debug": true,
"matchCondition": {
"methods": ["GET", "POST"],
"route": "/api/auth"
},
"backendUri": "http://localhost/api/auth",
"backendUri": "%API_LOCATION%/api/auth",
"requestOverrides": {
"backend.request.querystring.code": "",
"backend.request.querystring._code": "{request.querystring.code}"