Skip to content

Commit

Permalink
fix: CORS
Browse files Browse the repository at this point in the history
Signed-off-by: 0x73746F66 <[email protected]>
  • Loading branch information
0x73746F66 committed Jun 11, 2024
1 parent 648d6ae commit 465448a
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.autoClosingBrackets": "always"
},
"[markdown]": {
Expand All @@ -22,7 +22,7 @@
"editor.defaultFormatter": "vscode.json-language-features"
},
"[vue]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.defaultFormatter": "Vue.volar"
},
"volar.preview.port": 3000,
"volar.completion.preferredTagNameCase": "pascal",
Expand Down
20 changes: 20 additions & 0 deletions functions/_middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Respond to OPTIONS method
export const onRequestOptions: PagesFunction = async () => {
return new Response(null, {
status: 204,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Max-Age': '86400',
},
});
};

// Set CORS to all /api responses
export const onRequest: PagesFunction = async (context) => {
const response = await context.next();
response.headers.set('Access-Control-Allow-Origin', '*');
response.headers.set('Access-Control-Max-Age', '86400');
return response;
};
137 changes: 73 additions & 64 deletions src/pages/GitHub.vue
Original file line number Diff line number Diff line change
@@ -1,75 +1,84 @@
<script setup>
import { useTheme } from 'vuetify';
import { useTheme } from 'vuetify'
const { global } = useTheme()
const integrations = []
const urlQuery = Object.fromEntries(location.search.substring(1).split('&').map(item => item.split('=').map(decodeURIComponent)))
if (urlQuery?.setup_action === 'install') {
console.log('urlQuery', urlQuery)
if (urlQuery?.code) {
const url = new URL("https://github.com/login/oauth/access_token")
url.search = new URLSearchParams({
code: urlQuery.code,
client_id: 'Iv23liW5R5lkjMRgFrWI',
client_secret: '33e8e3bd7c04a4d2bf0a80b8c2d970c8056df085'
}).toString()
fetch(url, {
method: 'POST',
mode: 'no-cors',
})
.then(console.log)
.catch(console.log)
}
}
const redirect = () => {
location.href = 'https://github.com/apps/trivial-triage/installations/new/'
// /github-integration?code=c1ed5cbf17e7a98da805&installation_id=51710144&setup_action=install
const install = () => {
location.href = 'https://github.com/apps/trivial-triage/installations/new/'
}
</script>
<template>
<VRow>
<VCol cols="12">
<VCard title="GitHub">
<VCardText>
<VBtn
text="Connect to GitHub"
prepend-icon="mdi-github"
variant="text"
:color="global.name.value === 'dark' ? '#fff' : '#272727'"
@click="redirect"
/>
</VCardText>
<VTable
height="80%"
fixed-header
>
<thead>
<tr>
<th class="text-uppercase">
Repository
</th>
<th>
Public
</th>
<th>
Target
</th>
<th>
Type
</th>
<th>
Dependency count
</th>
</tr>
</thead>
<VRow>
<VCol cols="12">
<VCard title="GitHub">
<VCardText>
<VBtn text="Connect to GitHub" prepend-icon="mdi-github" variant="text"
:color="global.name.value === 'dark' ? '#fff' : '#272727'" @click="install" />
</VCardText>
<VTable height="80%" fixed-header>
<thead>
<tr>
<th class="text-uppercase">
Repository
</th>
<th>
Public
</th>
<th>
Target
</th>
<th>
Type
</th>
<th>
Dependency count
</th>
</tr>
</thead>
<tbody>
<tr
v-for="item in integrations"
:key="item.uuid"
>
<td>
{{ item.repo }}
</td>
<td class="text-center">
{{ item.visibility }}
</td>
<td class="text-center">
{{ item.target }}
</td>
<td class="text-center">
{{ item.type }}
</td>
<td class="text-center">
{{ item.Dependencies.length }}
</td>
</tr>
</tbody>
</VTable>
</VCard>
</VCol>
</VRow>
<tbody>
<tr v-for="item in integrations" :key="item.uuid">
<td>
{{ item.repo }}
</td>
<td class="text-center">
{{ item.visibility }}
</td>
<td class="text-center">
{{ item.target }}
</td>
<td class="text-center">
{{ item.type }}
</td>
<td class="text-center">
{{ item.Dependencies.length }}
</td>
</tr>
</tbody>
</VTable>
</VCard>
</VCol>
</VRow>
</template>

0 comments on commit 465448a

Please sign in to comment.