initial commit
This commit is contained in:
commit
36002bb247
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
FROM denoland/deno:2.3.1
|
||||||
|
|
||||||
|
RUN mkdir /app
|
||||||
|
WORKDIR /app
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
ENTRYPOINT ["deno", "serve", "--unstable-sloppy-imports", "/app"]
|
42
index.ts
Normal file
42
index.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import { Buffer } from "node:buffer"
|
||||||
|
import { inflateRawSync } from "node:zlib"
|
||||||
|
import { parse as parseXML } from "https://deno.land/x/xml@6.0.4/parse.ts"
|
||||||
|
|
||||||
|
const corsHeaders = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'OPTIONS, POST' }
|
||||||
|
|
||||||
|
export default {
|
||||||
|
async fetch(req) {
|
||||||
|
if (req.method === 'OPTIONS') return new Response("OK", { headers: corsHeaders })
|
||||||
|
if (req.method !== 'POST') return new Response("Only POST requests are allowed.", { status: 400 })
|
||||||
|
const uri = new URL(req.url)
|
||||||
|
const query = new URLSearchParams(uri.search)
|
||||||
|
let buffer, inflated, output = null
|
||||||
|
|
||||||
|
const body = req.body && await req.text() || false
|
||||||
|
if (!body) return new Response('POST request must have a body', { status: 400 })
|
||||||
|
|
||||||
|
try {
|
||||||
|
buffer = Buffer.from(body, 'base64')
|
||||||
|
if (!buffer) return new Response('Failed to convert body to Buffer.', { status: 500 })
|
||||||
|
} catch (err) {
|
||||||
|
return new Response(`Failed to convert body to Buffer: ${err}`, { status: 500 })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
inflated = inflateRawSync(buffer)
|
||||||
|
if (!inflated) return new Response('Failed to inflate Buffer.', { status: 500 })
|
||||||
|
} catch (err) {
|
||||||
|
return new Response(`Failed to inflate Buffer: ${err}`, { status: 500 })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
output = inflated.toString('utf-8')
|
||||||
|
if (!output) return new Response('Failed to convert output to UTF-8.', { status: 500 })
|
||||||
|
} catch (err) {
|
||||||
|
return new Response(`Failed to convert output to UTF-8: ${err}`, { status: 500 })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.has('json')) output = JSON.stringify(parseXML(output))
|
||||||
|
return new Response(output)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user