File tree Expand file tree Collapse file tree 4 files changed +25
-38
lines changed
Expand file tree Collapse file tree 4 files changed +25
-38
lines changed Original file line number Diff line number Diff line change 11node_modules
2+ .env
Original file line number Diff line number Diff line change 11'use strict' ;
22
3- const http = require ( 'http' ) ;
43const fetch = require ( 'node-fetch' ) ;
54
65const AUTH = `Basic ${ Buffer . from ( `engine262-bot:${ process . env . GH_TOKEN } ` ) . toString ( 'base64' ) } ` ;
@@ -31,40 +30,16 @@ function createGist(content, state) {
3130 . then ( ( r ) => r . json ( ) ) ;
3231}
3332
34- const server = http . createServer ( ( req , res ) => {
33+ module . exports = ( req , res ) => {
3534 if ( req . headers . origin !== 'https://engine262.js.org' ) {
36- res . writeHead ( 403 ) ;
37- res . end ( '403' ) ;
38- return ;
39- }
40- if ( req . url !== '/gist' ) {
41- res . writeHead ( 404 ) ;
42- res . end ( '404' ) ;
43- return ;
35+ return res . status ( 403 ) . send ( '403' ) ;
4436 }
4537 if ( req . method !== 'POST' ) {
46- res . writeHead ( 405 ) ;
47- res . end ( '405' ) ;
48- return ;
38+ return res . status ( 405 ) . send ( '405' ) ;
4939 }
50- let body = '' ;
51- req . on ( 'data' , ( chunk ) => {
52- body += chunk ;
53- } ) ;
54- req . on ( 'end' , ( ) => {
55- Promise . resolve ( )
56- . then ( ( ) => JSON . parse ( body ) )
57- . then ( ( { content, state } ) => createGist ( content , state ) )
58- . then ( ( data ) => {
59- res . writeHead ( 200 , { 'Content-Type' : 'application/json' } ) ;
60- res . end ( JSON . stringify ( data ) ) ;
61- } )
62- . catch ( ( e ) => {
63- console . error ( e ) ; // eslint-disable-line no-console
64- res . writeHead ( 500 ) ;
65- res . end ( '500' ) ;
66- } ) ;
67- } ) ;
68- } ) ;
69-
70- server . listen ( 5000 ) ;
40+ if ( ! req . body || ! req . body . content || ! req . body . state ) {
41+ return res . status ( 400 ) . send ( '400' ) ;
42+ }
43+ return createGist ( req . body . content , req . body . state )
44+ . then ( ( body ) => res . status ( 200 ) . json ( body ) ) ;
45+ } ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " engine262-api" ,
3+ "version" : 2 ,
4+ "routes" : [
5+ { "src" : " /api/gist" , "dest" : " /api/gist.js" },
6+ {
7+ "src" : " .*" ,
8+ "status" : 302 ,
9+ "headers" : { "Location" : " https://engine262.js.org" }
10+ }
11+ ],
12+ "env" : {
13+ "GH_TOKEN" : " @gh_token"
14+ }
15+ }
Original file line number Diff line number Diff line change 22 "name" : " server" ,
33 "version" : " 1.0.0" ,
44 "description" : " " ,
5- "main" : " index.js" ,
6- "scripts" : {
7- "start" : " node index.js"
8- },
95 "author" : " " ,
106 "license" : " MIT" ,
117 "dependencies" : {
You can’t perform that action at this time.
0 commit comments