Skip to content

Commit

Permalink
feat(server): add mock code saver API
Browse files Browse the repository at this point in the history
  • Loading branch information
ls-infra committed Oct 13, 2024
1 parent e874521 commit b3b7bc1
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 39 deletions.
61 changes: 42 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 20 additions & 19 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,26 @@
}
},
"dependencies": {
"@codingame/monaco-vscode-configuration-service-override": "~10.0.2",
"@codingame/monaco-vscode-files-service-override": "~10.0.2",
"@codingame/monaco-vscode-groovy-default-extension": "~10.0.2",
"@codingame/monaco-vscode-keybindings-service-override": "~10.0.2",
"@codingame/monaco-vscode-lifecycle-service-override": "~10.0.2",
"@codingame/monaco-vscode-localization-service-override": "~10.0.2",
"@codingame/monaco-vscode-java-default-extension": "~10.0.2",
"@codingame/monaco-vscode-javascript-default-extension": "~10.0.2",
"@codingame/monaco-vscode-json-default-extension": "~10.0.2",
"@codingame/monaco-vscode-python-default-extension": "~10.0.2",
"@codingame/monaco-vscode-standalone-languages": "~10.0.2",
"@codingame/monaco-vscode-standalone-typescript-language-features": "~10.0.2",
"@codingame/monaco-vscode-standalone-json-language-features": "~10.0.2",
"@codingame/monaco-vscode-textmate-service-override": "~10.0.2",
"@codingame/monaco-vscode-theme-defaults-default-extension": "~10.0.2",
"@codingame/monaco-vscode-theme-service-override": "~10.0.2",
"@codingame/monaco-vscode-typescript-basics-default-extension": "~10.0.2",
"@codingame/monaco-vscode-typescript-language-features-default-extension": "~10.0.2",
"@typefox/monaco-editor-react": "~6.0.09.0.0-next.3",
"@codingame/monaco-vscode-configuration-service-override": "~10.0.1",
"@codingame/monaco-vscode-files-service-override": "~10.0.1",
"@codingame/monaco-vscode-groovy-default-extension": "~10.0.1",
"@codingame/monaco-vscode-keybindings-service-override": "~10.0.1",
"@codingame/monaco-vscode-lifecycle-service-override": "~10.0.1",
"@codingame/monaco-vscode-localization-service-override": "~10.0.1",
"@codingame/monaco-vscode-java-default-extension": "~10.0.1",
"@codingame/monaco-vscode-javascript-default-extension": "~10.0.1",
"@codingame/monaco-vscode-json-default-extension": "~10.0.1",
"@codingame/monaco-vscode-python-default-extension": "~10.0.1",
"@codingame/monaco-vscode-standalone-languages": "~10.0.1",
"@codingame/monaco-vscode-standalone-typescript-language-features": "~10.0.1",
"@codingame/monaco-vscode-standalone-json-language-features": "~10.0.1",
"@codingame/monaco-vscode-textmate-service-override": "~10.0.1",
"@codingame/monaco-vscode-theme-defaults-default-extension": "~10.0.1",
"@codingame/monaco-vscode-theme-service-override": "~10.0.1",
"@codingame/monaco-vscode-typescript-basics-default-extension": "~10.0.1",
"@codingame/monaco-vscode-typescript-language-features-default-extension": "~10.0.1",
"@typefox/monaco-editor-react": "~6.0.0-next.2",
"cors": "^2.8.5",
"express": "~4.21.1",
"langium": "~3.2.0",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@~10.0.2",
Expand Down
22 changes: 21 additions & 1 deletion packages/examples/src/json/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* ------------------------------------------------------------------------------------------ */

import { resolve } from 'node:path';
import cors from 'cors';

import { runLanguageServer } from '../../common/node/language-server-runner.js';
import { LanguageName } from '../../common/node/server-commons.js';

import express from 'express';
export const runJsonServer = (baseDir: string, relativeDir: string) => {
const processRunPath = resolve(baseDir, relativeDir);
runLanguageServer({
Expand All @@ -23,4 +25,22 @@ export const runJsonServer = (baseDir: string, relativeDir: string) => {
perMessageDeflate: false
}
});

startMockHttpServerForSavingCodeFromEditor();
};

export const startMockHttpServerForSavingCodeFromEditor = () => {
const app = express();
app.use(cors());
app.use(express.json());
app.post('/save-code', (req, res) => {
const { code } = req.body;
console.log('Received code:', code);
res.json({ success: true, message: code});
});

const PORT = 3003;
app.listen(PORT, () => {
console.log(`JSON server running on port ${PORT}`);
});
}

0 comments on commit b3b7bc1

Please sign in to comment.