git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
66c6509
Branches
Tags
develop-client_server
master
typescript
fs-words.git
server
source
server.ts
[mod] server
Christian Fraß
commited
66c6509
at 2021-03-12 00:48:04
server.ts
Blame
History
Raw
namespace ns_server { /** */ async function query ( data_in : any ) : Promise<any> { console.info("[>>] query |", data_in); const data_out : any = await api.query(data_in["action"], data_in["input"]); console.info("[<<] query |", data_out); return Promise.resolve<any>(data_out); } /** */ async function query_http ( http_request : lib_http.type_request ) : Promise<lib_http.type_response> { // console.info("[>>] query_http |", http_request); let http_response : lib_http.type_response; switch (http_request.method) { case lib_http.enum_method.options: { http_response = { "statuscode": 200, "headers": { "Allow": "OPTIONS, POST", "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "OPTIONS,POST", "Access-Control-Allow-Headers": "Content-Type", }, "body": "", }; break; } case lib_http.enum_method.post: { const data_in : any = lib_code.json_decode(http_request.body); try { const data_out : any = await query(data_in); http_response = { "statuscode": 200, "headers": { "Allow": "OPTIONS, POST", "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "OPTIONS,POST", "Access-Control-Allow-Headers": "Content-Type", "Content-Type": "application/json", }, "body": lib_code.json_encode(data_out), }; } catch (exception) { console.error(exception); const data_out : any = {}; http_response = { "statuscode": 500, "headers": { "Allow": "OPTIONS, POST", "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "OPTIONS,POST", "Access-Control-Allow-Headers": "Content-Type", "Content-Type": "application/json", }, "body": lib_code.json_encode(data_out), }; } break; } } // console.info("[<<] query_http |", http_response); return Promise.resolve<lib_http.type_response>(http_response); } /** */ export async function query_http_raw ( input_raw : string ) : Promise<string> { // console.info("[>>] query_http_raw |", input_raw); const http_request : lib_http.type_request = lib_http.decode_request(input_raw); const http_response : lib_http.type_response = await query_http(http_request); const output_raw : string = lib_http.encode_response(http_response); // console.info("[<<] query_http_raw |", output_raw); return Promise.resolve<string>(output_raw); } }