Skip to content

Commit

Permalink
setup simple routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Z3rio committed Sep 13, 2023
1 parent bc58b77 commit 9f770c7
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 52 deletions.
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

Empty file added .yarn.installed
Empty file.
12 changes: 4 additions & 8 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
fx_version "cerulean"
game "gta5"
author "fbrp"
name "template"
description 'Template for FBRP resources'
version '1.0.0'
fx_version("cerulean")
game("gta5")

client_script "build/client.js"
server_script "build/server.js"
client_script("build/client.js")
server_script("build/server.js")
6 changes: 3 additions & 3 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"watch": ["src/**"],
"ext": "ts js",
"exec": "esbuild client=src/client/client.ts server=src/server/server.ts shared=src/server/server.ts --bundle --outdir=build --target=es2015 --platform=node && eslint . --ext .ts"
"watch": ["src/**"],
"ext": "ts js",
"exec": "esbuild client=src/client/client.ts server=src/server/server.ts --bundle --outdir=build --target=es2015 --platform=node && eslint . --ext .ts"
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"lint": "eslint . --ext .ts",
"lint-fix": "eslint . --ext .ts --fix",
"build": "esbuild client=src/client/client.ts server=src/server/server.ts shared=src/shared/shared.ts --bundle --outdir=build --minify --target=es2015 --platform=node",
"build": "esbuild client=src/client/client.ts server=src/server/server.ts --bundle --outdir=build --minify --target=es2015 --platform=node",
"dev": "nodemon"
},
"author": "",
Expand All @@ -17,11 +17,13 @@
"@types/node": "^18.7.14",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@zerio2/qbcore.js": "^1.5.4",
"esbuild": "^0.15.6",
"eslint": "^8.39.0"
},
"dependencies": {
"@fornuftbergets/fbrp-core": "^1.0.2",
"@types/express": "^4.17.17",
"express": "^4.18.2",
"nodemon": "^2.0.19"
}
}
3 changes: 0 additions & 3 deletions src/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
// import { Tools as CTools } from '@fornuftbergets/fbrp-core/client'
import { hello } from '../shared/shared'

hello("client")
13 changes: 4 additions & 9 deletions src/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"./**/*",
"../shared"
],
"exclude": [
"**/node_modules"
]
}
"include": ["./**/*", "../shared"],
"exclude": ["**/node_modules"]
}
54 changes: 51 additions & 3 deletions src/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
// import { Tools as STools } from '@fornuftbergets/fbrp-core/shared'
import { hello } from '../shared/shared'
import express, { Express, Request, Response } from "express";
import { Server } from "@zerio2/qbcore.js";
import { port, Resource } from "../shared";

hello("server")
const app: Express = express();
const qbcore: Server = global.exports["qb-core"].GetCoreObject();

app.get("/players/count", (_req: Request, res: Response) => {
const players = qbcore.Functions.GetQBPlayers();

if (Array.isArray(players)) {
res.status(200);
res.json({
count: players.length,
});
} else {
res.status(500);
res.json({
err: "Players was an object and not array",
});
}
});

app.get("/resources/list", (_req: Request, res: Response) => {
const resources: Record<string, Resource> = {};

for (let i = 1; i < GetNumResources(); i++) {
const resourceName = GetResourceByFindIndex(i);

resources[resourceName] = {
name: resourceName,
version: GetResourceMetadata(resourceName, "version", 0),
status: GetResourceState(resourceName),
};
}

res.status(200);
res.json({
list: resources,
});
});

app.all("*", function (_req: Request, res: Response) {
res.status(400);
res.json({
err: "Unknown route",
});
});

app.listen(port, () => {
console.log(`FiveM.nvim API is listening on port ${port}`);
});
15 changes: 4 additions & 11 deletions src/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@
"outDir": "./build",
"strict": true,
"moduleResolution": "node",
"types": [
"@citizenfx/server",
"@types/node"
],
"types": ["@citizenfx/server", "@types/node"],
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"./**/*"
],
"exclude": [
"**/node_modules"
]
}
"include": ["./**/*"],
"exclude": ["**/node_modules"]
}
1 change: 1 addition & 0 deletions src/shared/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const port = 6969;
2 changes: 2 additions & 0 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./data";
export * from "./structs";
4 changes: 0 additions & 4 deletions src/shared/shared.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/shared/structs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Resource {
status: string;
name: string;
version: string;
}
10 changes: 3 additions & 7 deletions src/shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"./**/*"
],
"exclude": [
"**/node_modules"
]
}
"include": ["./**/*"],
"exclude": ["**/node_modules"]
}

0 comments on commit 9f770c7

Please sign in to comment.