This commit is contained in:
Ishaan Dey
2024-05-25 20:13:31 -07:00
parent 08a898a82a
commit 74bb83f3ed
8 changed files with 87 additions and 103 deletions

View File

@ -237,7 +237,9 @@ export default {
const res = await db.query.user.findFirst({
where: (user, { eq }) => eq(user.id, id),
with: {
sandbox: true,
sandbox: {
orderBy: (sandbox, { desc }) => [desc(sandbox.createdAt)],
},
usersToSandboxes: true,
},
});

View File

@ -16,13 +16,13 @@ COPY . .
RUN npm run build
# Security: Create non-root user and assign ownership
RUN useradd -m sboxuser
RUN mkdir projects && chown -R sboxuser:sboxuser projects
USER sboxuser
RUN useradd -m appuser
RUN mkdir projects && chown -R appuser:appuser projects
USER appuser
# user namespace mapping
# todo user namespace mapping
EXPOSE 8000
EXPOSE 5173
EXPOSE 3000
EXPOSE 4000
CMD [ "node", "dist/index.js" ]

View File

@ -51,19 +51,21 @@ const terminals: {
const dirName = path.join(__dirname, "..");
const handshakeSchema = z.object({
userId: z.string(),
sandboxId: z.string(),
EIO: z.string(),
transport: z.string(),
});
io.use(async (socket, next) => {
console.log("Middleware");
const handshakeSchema = z.object({
userId: z.string(),
sandboxId: z.string(),
EIO: z.string(),
transport: z.string(),
});
const q = socket.handshake.query;
const parseQuery = handshakeSchema.safeParse(q);
if (!parseQuery.success) {
("Invalid request.");
console.log("Invalid request.");
next(new Error("Invalid request."));
return;
}
@ -75,6 +77,7 @@ io.use(async (socket, next) => {
const dbUserJSON = (await dbUser.json()) as User;
if (!dbUserJSON) {
console.log("DB error.");
next(new Error("DB error."));
return;
}
@ -85,6 +88,7 @@ io.use(async (socket, next) => {
);
if (!sandbox && !sharedSandboxes) {
console.log("Invalid credentials.");
next(new Error("Invalid credentials."));
return;
}
@ -145,6 +149,7 @@ io.on("connection", async (socket) => {
// todo: send diffs + debounce for efficiency
socket.on("saveFile", async (fileId: string, body: string) => {
console.log("save");
try {
await saveFileRL.consume(data.userId, 1);
@ -470,5 +475,5 @@ io.on("connection", async (socket) => {
});
httpServer.listen(port, () => {
console.log(`Server, running on port ${port}`);
console.log(`Server 123, running on port ${port}`);
});

View File

@ -56,8 +56,9 @@ import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
server: {
port: 8000,
},
port: 3000,
host: "0.0.0.0",
}
})
`,
},
@ -87,10 +88,12 @@ export default defineConfig({
flex-direction: column;
align-items: center;
justify-content: center;
font-family: sans-serif;
}
h1 {
color: #fff;
color: #000;
margin: 0;
}