Skip to content

Commit

Permalink
✨ Feature: add server response headers for CORS (#939)
Browse files Browse the repository at this point in the history
Co-authored-by: long <iamlongalong@gmail.com>
  • Loading branch information
iamlongalong and long authored Jul 16, 2022
1 parent 0a9e169 commit fb69bad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/main/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ class Server {
}

private handleRequest = (request: http.IncomingMessage, response: http.ServerResponse) => {
if (request.method === 'OPTIONS') {
handleResponse({
response
})
return
}

if (request.method === 'POST') {
if (!routers.getHandler(request.url!)) {
logger.warn(`[PicGo Server] don't support [${request.url}] url`)
handleResponse({
response,
statusCode: 404,
header: {},
body: {
success: false
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ export const handleResponse = ({
response,
statusCode = 200,
header = {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'access-control-allow-headers': '*',
'access-control-allow-methods': 'POST, GET, OPTIONS',
'access-control-allow-origin': '*'
},
body = {
success: false
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/pages/Plugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ export default class extends Vue {
pluginNameList: string[] = []
loading = true
needReload = false
pluginListToolTip = this.$T('PLUGIN_LIST')importLocalPluginToolTip = this.$T('PLUGIN_IMPORT_LOCAL')
pluginListToolTip = this.$T('PLUGIN_LIST')
importLocalPluginToolTip = this.$T('PLUGIN_IMPORT_LOCAL')
id = ''
os = ''
defaultLogo: string = 'this.src="https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo@dev/public/roundLogo.png"'
Expand Down

0 comments on commit fb69bad

Please sign in to comment.