diff --git a/ConnectForce.code-workspace b/ConnectForce.code-workspace index 754bf52..252e840 100644 --- a/ConnectForce.code-workspace +++ b/ConnectForce.code-workspace @@ -4,10 +4,6 @@ "name": "ConnectForce", "path": "./packages/game" }, - { - "name": "Server", - "path": "./packages/server" - }, { "name": "Solution Items", "path": "." @@ -117,29 +113,7 @@ "preLaunchTask": "Build", "pathMapping": { "/": "${workspaceFolder:ConnectForce}/src" - }, - "presentation": { - "hidden": true } - }, - { - "type": "node", - "request": "launch", - "name": "Launch Server", - "program": "${workspaceFolder:Server}/src/main.js", - "console": "integratedTerminal", - "presentation": { - "hidden": true - } - } - ], - "compounds": [ - { - "name": "Launch Project in Chrome", - "configurations": [ - "Launch Website in Chrome", - "Launch Server" - ] } ] }, diff --git a/packages/game/gulpfile.ts b/packages/game/gulpfile.ts index 2aae21a..2b74e68 100644 --- a/packages/game/gulpfile.ts +++ b/packages/game/gulpfile.ts @@ -137,7 +137,7 @@ export let Watch: TaskFunction = async (): Promise => syncer.init({ open: false, - proxy: "http://localhost:1337", + server: join(context.StaticPath()), online: false }); diff --git a/packages/server/.eslintrc.cjs b/packages/server/.eslintrc.cjs deleted file mode 100644 index dffa289..0000000 --- a/packages/server/.eslintrc.cjs +++ /dev/null @@ -1,13 +0,0 @@ -const { join } = require("node:path"); - -module.exports = { - env: { - browser: true - }, - parserOptions: { - project: [ - join(__dirname, "app.jsconfig.json"), - join(__dirname, "eslint.jsconfig.json") - ] - } -}; diff --git a/packages/server/.npmignore b/packages/server/.npmignore deleted file mode 100644 index b04af65..0000000 --- a/packages/server/.npmignore +++ /dev/null @@ -1,168 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variable files -.env -.env.development.local -.env.test.local -.env.production.local -.env.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next -out - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and *not* Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# vuepress v2.x temp and cache directory -.temp -.cache - -# Docusaurus cache and generated files -.docusaurus - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* - -# Source-files -[Ss]rc/ - -# TypeScript config-files -tsconfig.json -tsconfig.*.json - -# Lint config-files -.eslintrc -.eslintrc.* - -# Source-maps -[Ll]ib/**/*.map - -# Unit-Tests -.mocharc.* -[Ll]ib/tests/ - -# Visual Studio Code-Environment -.vscode/ - -# GitHub configuration -.github/ - -# CI configuration -.drone.yml -.woodpecker.yml - -# Build Environment -gulp/ -gulpfile.ts - -# Temporary release-assets -.tagName.txt -.tagHeading.txt -.releaseNotes.md -.releaseTitle.md diff --git a/packages/server/app.jsconfig.json b/packages/server/app.jsconfig.json deleted file mode 100644 index 07b883f..0000000 --- a/packages/server/app.jsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "./tsconfig.base.json", - "compilerOptions": { - "allowJs": true, - "checkJs": true, - "composite": true - }, - "include": [ - "./src/**/*" - ] -} diff --git a/packages/server/eslint.jsconfig.json b/packages/server/eslint.jsconfig.json deleted file mode 100644 index df23cb5..0000000 --- a/packages/server/eslint.jsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.base.json", - "compilerOptions": { - "allowJs": true, - "checkJs": true - }, - "include": [ - "./.eslintrc.cjs" - ] -} diff --git a/packages/server/package.json b/packages/server/package.json deleted file mode 100644 index 4d61558..0000000 --- a/packages/server/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "connect-force-server", - "version": "0.0.0", - "type": "module", - "description": "A server for Storing ConnectForce Savegames", - "author": "Manuel Thalmann ", - "scripts": { - "start": "noderel -e ./src/main.js" - }, - "dependencies": { - "express": "^4.18.2", - "randexp": "^0.5.3" - }, - "devDependencies": { - "@types/express": "^4.17.15", - "@types/node": "^18.11.15", - "noderel": "^1.0.13" - } -} diff --git a/packages/server/src/HTTPError.js b/packages/server/src/HTTPError.js deleted file mode 100644 index 8317c7b..0000000 --- a/packages/server/src/HTTPError.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Represents an http error. - */ -export class HTTPError extends Error -{ - /** - * The http status code. - * - * @type {number} - */ - status; - - /** - * Initializes a new instance of the {@link HTTPError `HTTPError`} class. - * - * @param {number} status - * The http status code. - * - * @param {string} message - * The error message. - */ - constructor(status, message) - { - super(message); - this.status = status; - } -} diff --git a/packages/server/src/main.js b/packages/server/src/main.js deleted file mode 100644 index 6db98c8..0000000 --- a/packages/server/src/main.js +++ /dev/null @@ -1,150 +0,0 @@ -import { join } from "path"; -import { fileURLToPath } from "url"; -import express from "express"; -import RandExp from "randexp"; -import { HTTPError } from "./HTTPError.js"; - -const { randexp } = RandExp; - -const dirname = fileURLToPath(new URL(".", import.meta.url)); -const app = express(); - -const apiKeys = [ - "c4game" -]; - -const dataPath = "/api/data"; -const parametrizedDataPath = "/api/data/:id"; - -/** - * The data provided by the api. - * - * @type {Record} - */ -let data = {}; - -/** - * Creates a new guid. - * - * @returns {string} - * The newly created guid. - */ -function createGuid() -{ - return randexp(/[0-9a-f]{8}(-[0-9a-f]{4}){4}[0-9a-f]{8}/); -} - -app.use(express.static(join(dirname, "..", "..", "game", "lib", "static"))); -app.use("/api", express.json()); - -app.use( - "/api", - (request, response, next) => - { - const keyParam = "token"; - - if (keyParam in request.query) - { - let key = request.query[keyParam]; - - if (typeof key === "string" && apiKeys.includes(key)) - { - next(); - } - else - { - next(new HTTPError(401, "The specified API token is invalid")); - } - } - else - { - next(new HTTPError(401, "An API token is required")); - } - }); - -app.get( - parametrizedDataPath, - (request, response, next) => - { - let id = request.params.id; - console.log(`Data ID \`${id}\` requested`); - - if (id in data) - { - response.send(data[id]); - } - else - { - next(); - } - }); - -app.post( - dataPath, - (request, response, next) => - { - let id = createGuid(); - data[id] = request.body; - response.send({ id }); - }); - -app.put( - parametrizedDataPath, - (request, response, next) => - { - let id = request.params.id; - - if (id in data) - { - data[id] = request.body; - response.send(data[id]); - } - else - { - next(); - } - }); - -app.delete( - parametrizedDataPath, - (request, response, next) => - { - let id = request.params.id; - - if (id in data) - { - delete data[id]; - response.send(); - response.status(204); - } - else - { - next(); - } - }); - -app.use( - [ - (error, request, response, next) => - { - response.send(`${error}`); - response.status(error instanceof HTTPError ? error.status : 500); - } - ]); - -app.use( - "/api", - (request, response) => - { - response.send({ error: "Not Found" }); - response.status(404); - }); - -app.use( - (request, response) => - { - response.send("Not Found"); - response.status(404); - }); - -app.listen(1337); diff --git a/packages/server/tsconfig.base.json b/packages/server/tsconfig.base.json deleted file mode 100644 index 02ec15a..0000000 --- a/packages/server/tsconfig.base.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../tsconfig.base.json" -} diff --git a/packages/server/tsconfig.json b/packages/server/tsconfig.json deleted file mode 100644 index d16ea8d..0000000 --- a/packages/server/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "./tsconfig.base.json", - "references": [ - { - "path": "./app.jsconfig.json" - }, - { - "path": "./eslint.jsconfig.json" - } - ], - "include": [] -}