Rename index.js to requirements.txt
Browse files- index.js +0 -76
- requirements.txt +7 -0
index.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
| 1 |
-
require("dotenv").config();
|
| 2 |
-
const express = require("express");
|
| 3 |
-
const fetch = require("node-fetch");
|
| 4 |
-
const app = express();
|
| 5 |
-
|
| 6 |
-
app.use(express.urlencoded({ extended: true }));
|
| 7 |
-
app.use(express.json());
|
| 8 |
-
|
| 9 |
-
const CODESANDBOX_API = "https://api.codesandbox.io/graphql";
|
| 10 |
-
const BEARER_TOKEN = process.env.CODESANDBOX_TOKEN;
|
| 11 |
-
|
| 12 |
-
const createSandboxMutation = `
|
| 13 |
-
mutation {
|
| 14 |
-
createSandbox(input: { title: "API Sandbox" }) {
|
| 15 |
-
sandbox {
|
| 16 |
-
id
|
| 17 |
-
title
|
| 18 |
-
publicId
|
| 19 |
-
}
|
| 20 |
-
}
|
| 21 |
-
}
|
| 22 |
-
`;
|
| 23 |
-
|
| 24 |
-
async function graphqlRequest(query) {
|
| 25 |
-
const res = await fetch(CODESANDBOX_API, {
|
| 26 |
-
method: "POST",
|
| 27 |
-
headers: {
|
| 28 |
-
"Content-Type": "application/json",
|
| 29 |
-
"Authorization": `Bearer ${BEARER_TOKEN}`
|
| 30 |
-
},
|
| 31 |
-
body: JSON.stringify({ query })
|
| 32 |
-
});
|
| 33 |
-
|
| 34 |
-
const json = await res.json();
|
| 35 |
-
if (json.errors) {
|
| 36 |
-
throw new Error(JSON.stringify(json.errors));
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
return json.data;
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
app.get("/", (req, res) => {
|
| 43 |
-
res.send(`
|
| 44 |
-
<h2>π CodeSandbox Creator</h2>
|
| 45 |
-
<form action="/create" method="POST">
|
| 46 |
-
<button type="submit">π Create New Sandbox</button>
|
| 47 |
-
</form>
|
| 48 |
-
`);
|
| 49 |
-
});
|
| 50 |
-
|
| 51 |
-
app.post("/create", async (req, res) => {
|
| 52 |
-
try {
|
| 53 |
-
const result = await graphqlRequest(createSandboxMutation);
|
| 54 |
-
const sandbox = result.createSandbox.sandbox;
|
| 55 |
-
const link = `https://codesandbox.io/s/${sandbox.publicId}`;
|
| 56 |
-
|
| 57 |
-
res.send(`
|
| 58 |
-
<h3>β
Sandbox Created!</h3>
|
| 59 |
-
<p>Title: <b>${sandbox.title}</b></p>
|
| 60 |
-
<p>Open: <a href="${link}" target="_blank">${link}</a></p>
|
| 61 |
-
<a href="/">β¬
Back</a>
|
| 62 |
-
`);
|
| 63 |
-
} catch (error) {
|
| 64 |
-
console.error(error);
|
| 65 |
-
res.send(`
|
| 66 |
-
<h3>β Failed to create sandbox</h3>
|
| 67 |
-
<pre>${error.message}</pre>
|
| 68 |
-
<a href="/">β¬
Back</a>
|
| 69 |
-
`);
|
| 70 |
-
}
|
| 71 |
-
});
|
| 72 |
-
|
| 73 |
-
const PORT = process.env.PORT || 3000;
|
| 74 |
-
app.listen(PORT, () => {
|
| 75 |
-
console.log(`π App running at http://localhost:${PORT}`);
|
| 76 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi==0.95.2
|
| 2 |
+
uvicorn==0.22.0
|
| 3 |
+
requests==2.30.0
|
| 4 |
+
pydantic==1.10.9
|
| 5 |
+
boto3==1.26.76
|
| 6 |
+
httpx==0.24.0
|
| 7 |
+
aioboto3==11.2.0
|