Skip to content

Commit fb69bad

Browse files
iamlongalonglong
and
long
authored
✨ Feature: add server response headers for CORS (#939)
Co-authored-by: long <iamlongalong@gmail.com>
1 parent 0a9e169 commit fb69bad

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/main/server/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ class Server {
3939
}
4040

4141
private handleRequest = (request: http.IncomingMessage, response: http.ServerResponse) => {
42+
if (request.method === 'OPTIONS') {
43+
handleResponse({
44+
response
45+
})
46+
return
47+
}
48+
4249
if (request.method === 'POST') {
4350
if (!routers.getHandler(request.url!)) {
4451
logger.warn(`[PicGo Server] don't support [${request.url}] url`)
4552
handleResponse({
4653
response,
4754
statusCode: 404,
48-
header: {},
4955
body: {
5056
success: false
5157
}

src/main/server/utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ export const handleResponse = ({
44
response,
55
statusCode = 200,
66
header = {
7-
'Content-Type': 'application/json'
7+
'Content-Type': 'application/json',
8+
'access-control-allow-headers': '*',
9+
'access-control-allow-methods': 'POST, GET, OPTIONS',
10+
'access-control-allow-origin': '*'
811
},
912
body = {
1013
success: false

src/renderer/pages/Plugin.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ export default class extends Vue {
140140
pluginNameList: string[] = []
141141
loading = true
142142
needReload = false
143-
pluginListToolTip = this.$T('PLUGIN_LIST')importLocalPluginToolTip = this.$T('PLUGIN_IMPORT_LOCAL')
143+
pluginListToolTip = this.$T('PLUGIN_LIST')
144+
importLocalPluginToolTip = this.$T('PLUGIN_IMPORT_LOCAL')
144145
id = ''
145146
os = ''
146147
defaultLogo: string = 'this.src="https://cdn.jsdelivr.net/gh/Molunerfinn/PicGo@dev/public/roundLogo.png"'

0 commit comments

Comments
 (0)