revert to local hosting
This commit is contained in:
@ -1,47 +1,43 @@
|
||||
export interface Env {
|
||||
AI: any;
|
||||
KEY: string;
|
||||
AI: any
|
||||
}
|
||||
|
||||
export default {
|
||||
async fetch(request, env): Promise<Response> {
|
||||
if (request.method !== 'GET') {
|
||||
return new Response('Method Not Allowed', { status: 405 });
|
||||
}
|
||||
if (request.headers.get('Authorization') !== env.KEY) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
if (request.method !== "GET") {
|
||||
return new Response("Method Not Allowed", { status: 405 })
|
||||
}
|
||||
|
||||
const url = new URL(request.url);
|
||||
const fileName = url.searchParams.get('fileName');
|
||||
const instructions = url.searchParams.get('instructions');
|
||||
const line = url.searchParams.get('line');
|
||||
const code = url.searchParams.get('code');
|
||||
const url = new URL(request.url)
|
||||
const fileName = url.searchParams.get("fileName")
|
||||
const instructions = url.searchParams.get("instructions")
|
||||
const line = url.searchParams.get("line")
|
||||
const code = url.searchParams.get("code")
|
||||
|
||||
const response = await env.AI.run('@cf/meta/llama-3-8b-instruct', {
|
||||
const response = await env.AI.run("@cf/meta/llama-3-8b-instruct", {
|
||||
messages: [
|
||||
{
|
||||
role: 'system',
|
||||
role: "system",
|
||||
content:
|
||||
'You are an expert coding assistant. You read code from a file, and you suggest new code to add to the file. You may be given instructions on what to generate, which you should follow. You should generate code that is correct, efficient, and follows best practices. You should also generate code that is clear and easy to read. When you generate code, you should only return the code, and nothing else. You should not include backticks in the code you generate.',
|
||||
"You are an expert coding assistant. You read code from a file, and you suggest new code to add to the file. You may be given instructions on what to generate, which you should follow. You should generate code that is correct, efficient, and follows best practices. You should also generate code that is clear and easy to read. When you generate code, you should only return the code, and nothing else. You should not include backticks in the code you generate.",
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
role: "user",
|
||||
content: `The file is called ${fileName}.`,
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
role: "user",
|
||||
content: `Here are my instructions on what to generate: ${instructions}.`,
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
role: "user",
|
||||
content: `Suggest me code to insert at line ${line} in my file. Give only the code, and NOTHING else. DO NOT include backticks in your response. My code file content is as follows
|
||||
|
||||
${code}`,
|
||||
},
|
||||
],
|
||||
});
|
||||
})
|
||||
|
||||
return new Response(JSON.stringify(response));
|
||||
return new Response(JSON.stringify(response))
|
||||
},
|
||||
} satisfies ExportedHandler<Env>;
|
||||
} satisfies ExportedHandler<Env>
|
||||
|
@ -5,6 +5,3 @@ compatibility_flags = ["nodejs_compat"]
|
||||
|
||||
[ai]
|
||||
binding = "AI"
|
||||
|
||||
[vars]
|
||||
KEY = ""
|
||||
|
1
backend/server/.env.example
Normal file
1
backend/server/.env.example
Normal file
@ -0,0 +1 @@
|
||||
PORT=4000
|
@ -22,7 +22,7 @@ USER appuser
|
||||
|
||||
# todo user namespace mapping
|
||||
|
||||
EXPOSE 3000
|
||||
EXPOSE 5173
|
||||
EXPOSE 4000
|
||||
|
||||
CMD [ "node", "dist/index.js" ]
|
1157
backend/server/package-lock.json
generated
1157
backend/server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -11,7 +11,6 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-ecs": "^3.577.0",
|
||||
"concurrently": "^8.2.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.4.5",
|
||||
|
@ -6,35 +6,10 @@ import {
|
||||
TFile,
|
||||
TFileData,
|
||||
TFolder,
|
||||
User,
|
||||
} from "./types";
|
||||
|
||||
import {
|
||||
DeleteServiceCommand,
|
||||
DescribeServicesCommand,
|
||||
ECSClient,
|
||||
} from "@aws-sdk/client-ecs";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const client = new ECSClient({
|
||||
region: "us-east-1",
|
||||
credentials: {
|
||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
||||
},
|
||||
});
|
||||
|
||||
export const testDescribe = async () => {
|
||||
const command = new DescribeServicesCommand({
|
||||
cluster: "Sandbox",
|
||||
services: ["Sandbox"],
|
||||
});
|
||||
const response = await client.send(command);
|
||||
console.log("describing: ", response);
|
||||
return response;
|
||||
};
|
||||
|
||||
export const getSandboxFiles = async (id: string) => {
|
||||
const res = await fetch(
|
||||
`https://storage.ishaan1013.workers.dev/api?sandboxId=${id}`
|
||||
@ -176,18 +151,3 @@ export const getProjectSize = async (id: string) => {
|
||||
);
|
||||
return (await res.json()).size;
|
||||
};
|
||||
|
||||
export const stopServer = async (service: string) => {
|
||||
const command = new DeleteServiceCommand({
|
||||
cluster: process.env.AWS_ECS_CLUSTER!,
|
||||
service,
|
||||
force: true,
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await client.send(command);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error stopping server:", error);
|
||||
}
|
||||
};
|
||||
|
@ -1,8 +1,8 @@
|
||||
const startercode = {
|
||||
node: [
|
||||
{ name: 'index.js', body: `console.log("Hello World!")` },
|
||||
{ name: "index.js", body: `console.log("Hello World!")` },
|
||||
{
|
||||
name: 'package.json',
|
||||
name: "package.json",
|
||||
body: `{
|
||||
"name": "nodejs",
|
||||
"version": "1.0.0",
|
||||
@ -19,7 +19,7 @@ const startercode = {
|
||||
],
|
||||
react: [
|
||||
{
|
||||
name: 'package.json',
|
||||
name: "package.json",
|
||||
body: `{
|
||||
"name": "react",
|
||||
"private": true,
|
||||
@ -48,7 +48,7 @@ const startercode = {
|
||||
}`,
|
||||
},
|
||||
{
|
||||
name: 'vite.config.js',
|
||||
name: "vite.config.js",
|
||||
body: `import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
@ -56,14 +56,14 @@ import react from '@vitejs/plugin-react'
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
port: 3000,
|
||||
port: 5173,
|
||||
host: "0.0.0.0",
|
||||
}
|
||||
})
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: 'index.html',
|
||||
name: "index.html",
|
||||
body: `<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@ -80,7 +80,7 @@ export default defineConfig({
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: 'src/App.css',
|
||||
name: "src/App.css",
|
||||
body: `div {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
@ -108,7 +108,7 @@ button {
|
||||
}`,
|
||||
},
|
||||
{
|
||||
name: 'src/App.jsx',
|
||||
name: "src/App.jsx",
|
||||
body: `import './App.css'
|
||||
import { useState } from 'react'
|
||||
|
||||
@ -133,7 +133,7 @@ export default App
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: 'src/main.jsx',
|
||||
name: "src/main.jsx",
|
||||
body: `import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.jsx'
|
||||
@ -146,6 +146,6 @@ ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
`,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export default startercode;
|
||||
export default startercode
|
||||
|
Reference in New Issue
Block a user