Simple auth
This commit is contained in:
+7
-8
@@ -1,11 +1,10 @@
|
|||||||
export interface LiveRunMove {
|
var cookies: string | undefined;
|
||||||
latency: number;
|
|
||||||
cursor: number;
|
export function getCookies(): string | undefined {
|
||||||
changes?: {
|
return cookies;
|
||||||
from: number;
|
}
|
||||||
to: number;
|
export function setCookies(c: string) {
|
||||||
insert: string;
|
cookies = c;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function submitRun() {}
|
export async function submitRun() {}
|
||||||
|
|||||||
+13
-3
@@ -2,15 +2,16 @@ import * as vscode from "vscode";
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import * as http from "http";
|
import * as http from "http";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
|
import { getCookies, setCookies } from "./client";
|
||||||
|
|
||||||
let server: http.Server | undefined;
|
var server: http.Server | undefined;
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
app.use(express.json());
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
origin: (origin, callback) => {
|
origin: (origin, callback) => {
|
||||||
// allow requests with no origin (e.g., direct curl)
|
|
||||||
if (
|
if (
|
||||||
!origin ||
|
!origin ||
|
||||||
origin.includes("localhost") ||
|
origin.includes("localhost") ||
|
||||||
@@ -25,10 +26,19 @@ app.use(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app.post("/auth", (req, res) => {
|
||||||
|
const { saveCookies } = req.body;
|
||||||
|
|
||||||
|
setCookies(saveCookies);
|
||||||
|
|
||||||
|
res.json({ ok: true });
|
||||||
|
});
|
||||||
|
|
||||||
app.get("/start-run/:problemId", (req, res) => {
|
app.get("/start-run/:problemId", (req, res) => {
|
||||||
const { problemId } = req.params;
|
const { problemId } = req.params;
|
||||||
|
|
||||||
// trigger VS Code command
|
if (!getCookies()) return res.json({ ok: false, code: "auth" });
|
||||||
|
|
||||||
vscode.commands.executeCommand("devrun-vscode.startRun", problemId);
|
vscode.commands.executeCommand("devrun-vscode.startRun", problemId);
|
||||||
|
|
||||||
res.json({ ok: true, problemId });
|
res.json({ ok: true, problemId });
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
export interface LiveRunMove {
|
||||||
|
latency: number;
|
||||||
|
cursor: number;
|
||||||
|
changes?: {
|
||||||
|
from: number;
|
||||||
|
to: number;
|
||||||
|
insert: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user