Updated config and OPTIONS method for function.
This commit is contained in:
parent
8d5d20b703
commit
3eab01027b
@ -5,28 +5,6 @@ const baseurl = 'https://syncdb-service-d3f974de56ef.herokuapp.com/';
|
|||||||
const auth = 'admin:stM8Lnm@Cuf-tWZHv';
|
const auth = 'admin:stM8Lnm@Cuf-tWZHv';
|
||||||
const authToken = Buffer.from(auth).toString('base64');
|
const authToken = Buffer.from(auth).toString('base64');
|
||||||
|
|
||||||
function buildOptions(req: Request) {
|
|
||||||
if (req.method == 'OPTIONS') {
|
|
||||||
const origin = req.headers.get('Origin');
|
|
||||||
console.log(origin);
|
|
||||||
const res = new Response(
|
|
||||||
"",
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
'Allow': 'POST',
|
|
||||||
'Max-Age': '30',
|
|
||||||
'Access-Control-Allow-Methods': 'POST',
|
|
||||||
'Access-Control-Allow-Origin': origin ? origin : 'https://cameras.immersiveidea.com',
|
|
||||||
'Access-Control-Allow-Credentials': 'true'
|
|
||||||
},
|
|
||||||
status: 200
|
|
||||||
});
|
|
||||||
console.log(res);
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
username: string,
|
username: string,
|
||||||
@ -149,12 +127,26 @@ async function authorizeUser(params: Params) {
|
|||||||
export default async (req: Request, context: Context) => {
|
export default async (req: Request, context: Context) => {
|
||||||
console.log(req.method);
|
console.log(req.method);
|
||||||
|
|
||||||
const options = buildOptions(req);
|
if (req.method == 'OPTIONS') {
|
||||||
if (options != null) {
|
const origin = req.headers.get('Origin');
|
||||||
console.log('Options Call Found');
|
console.log(origin);
|
||||||
return options;
|
const res = new Response(
|
||||||
|
"",
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Allow': 'POST',
|
||||||
|
'Max-Age': '30',
|
||||||
|
'Access-Control-Allow-Methods': 'POST',
|
||||||
|
'Access-Control-Allow-Origin': origin ? origin : 'https://cameras.immersiveidea.com',
|
||||||
|
'Access-Control-Allow-Credentials': 'true'
|
||||||
|
},
|
||||||
|
status: 200
|
||||||
|
});
|
||||||
|
console.log(res);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const params = JSON.parse(await req.text());
|
const params = JSON.parse(await req.text());
|
||||||
console.log(params);
|
console.log(params);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user