Skip to content

Commit fae517c

Browse files
committed
maybe this will work
1 parent 7a0ebb1 commit fae517c

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

api/gist.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ module.exports = (req, res) => {
3434
if (req.headers.origin !== 'https://engine262.js.org') {
3535
return res.status(403).send('403');
3636
}
37+
if (req.method === 'OPTIONS') {
38+
res.writeHead(200, { 'Allow': 'OPTIONS, POST' });
39+
res.end();
40+
return res;
41+
}
3742
if (req.method !== 'POST') {
3843
return res.status(405).send('405');
3944
}
4045
if (!req.body || !req.body.content || !req.body.state) {
4146
return res.status(400).send('400');
4247
}
4348
return createGist(req.body.content, req.body.state)
44-
.then((body) => res.status(200).json(body));
49+
.then((body) => res.status(200).end(body.id));
4550
};

now.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"headers": {
99
"Access-Control-Allow-Origin": "https://engine262.js.org",
1010
"Access-Control-Allow-Headers": "content-type",
11-
"Access-Control-Allow-Methods": "POST"
11+
"Access-Control-Allow-Methods": "OPTIONS, POST"
1212
}
1313
},
1414
{

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22
"name": "server",
33
"dependencies": {
44
"node-fetch": "^2.6.0"
5+
},
6+
"devDependencies": {
7+
"babel-eslint": "^10.0.3",
8+
"eslint": "^6.1.0",
9+
"eslint-config-airbnb-base": "^14.0.0",
10+
"eslint-plugin-import": "^2.18.2"
511
}
612
}

src/state.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export function setState(name, value) {
9191
document.querySelector('#save-to-gist')
9292
.addEventListener('click', async () => {
9393
const s = await state;
94-
const body = await fetch('https://engine262-api.snek.now.sh/api/gist', {
94+
const id = await fetch('https://engine262-api.snek.now.sh/api/gist', {
9595
method: 'POST',
9696
headers: {
9797
'Content-Type': 'application/json',
@@ -104,8 +104,8 @@ document.querySelector('#save-to-gist')
104104
},
105105
}),
106106

107-
}).then((r) => r.json());
107+
}).then((r) => r.text());
108108
isGist = true;
109-
s.set('gist', body.id);
109+
s.set('gist', id);
110110
await updateState();
111111
});

0 commit comments

Comments
 (0)