Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kobakazu0429 committed Nov 5, 2023
1 parent d97046e commit 128f208
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
16 changes: 7 additions & 9 deletions src/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ type Response =
export async function compiler(src: string) {
compileLogOut(_("compiler.start"));

const param = {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
body: JSON.stringify({ src }),
};

const res = await (
await fetch(`${import.meta.env.VITE_API_SERVER_URL}/compile`, param)
await fetch("/compile", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ src }),
})
).json();

compileLogOut(_("compiler.finished"));
Expand Down
9 changes: 1 addition & 8 deletions src/editor/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ReconnectingWebSocket, {
} from "reconnecting-websocket";

export const connectLanguageServer = () => {
const url = createUrl("/lsp");
const url = normalizeUrl(`${location.origin}/lsp`);
const webSocket = createWebSocket(url);
webSocket.onopen = async () => {
const socket = toSocket(webSocket as any);
Expand Down Expand Up @@ -52,13 +52,6 @@ const createLanguageClient = (
});
};

const createUrl = (path: string): string => {
const protocol = location.protocol === "https:" ? "wss" : "ws";
return normalizeUrl(
`${protocol}://${import.meta.env.VITE_API_SERVER_DOMAIN}${path}`
);
};

const createWebSocket = (url: string): ReconnectingWebSocket => {
const socketOptions: ReconnectingWebSocketOptions = {
maxReconnectionDelay: 10000,
Expand Down
19 changes: 19 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ import { optimizeImports, optimizeCss } from "carbon-preprocess-svelte";
import path from "path";

export default defineConfig(({ mode }) => ({
server: {
proxy: {
"/compile": {
target:
mode === "production"
? "https://compiler.kaz.dev"
: "http://localhost:8081",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/compile/, ""),
},
"/lsp": {
target:
mode === "production" ? "wss://lsp.kaz.dev" : "ws://localhost:8082",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/lsp/, ""),
},
},
},

build: {
target: "es2019",
rollupOptions: {
Expand Down

0 comments on commit 128f208

Please sign in to comment.