Skip to content

Commit

Permalink
Prepare for frontend, move config examples
Browse files Browse the repository at this point in the history
  • Loading branch information
RubberDuckShobe committed May 17, 2023
1 parent 68460e7 commit ddd2182
Show file tree
Hide file tree
Showing 11 changed files with 767 additions and 46 deletions.
37 changes: 1 addition & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,4 @@ Replicates pretty much all of the original server's features, unless I've missed

# Config
The server uses two config files at the root of the project: ``wavebreaker_config.json`` and ``wavebreaker_radio_entries.json``.

Server config example:
```json
{
"port": 443,
"host": "0.0.0.0"
"https": {
"key": "./key.pem",
"cert": "./cert.pem",
"passphrase": "yeah"
},
"steamApiKey": "YOURKEYHERE",
"logger": true,
"environment": "development"
}
```

Radio config example:
```json
{
"availableSongs": [
{
"artist": "Wavebreaker",
"title": "Example entry 1",
"cgrFileUrl": "http://localhost/as/asradio/Test1.cgr",
"externalUrl": "https://github.com/AudiosurfResearch/Wavebreaker"
},
{
"artist": "Wavebreaker",
"title": "Example entry 2",
"cgrFileUrl": "http://localhost/as/asradio/Test2.cgr",
"externalUrl": "https://github.com/AudiosurfResearch/Wavebreaker"
}
]
}
```
Look at the example files in there, they should be self-explanatory.
Empty file added RadioSongs/.put_cgr_files_here
Empty file.
29 changes: 21 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import Fastify from "fastify";
import formbody from "@fastify/formbody";
import fastifyStatic from "@fastify/static";
import httpsRedirect from "fastify-https-redirect";
import fastifyJwt from "@fastify/jwt";
import WavebreakerConfig from "./wavebreaker_config.json";
import accountsRouter from "./routes/as1/accounts";
import gameplayRouter from "./routes/as1/gameplay";
import informationRouter from "./routes/as1/information";
import radioRouter from "./routes/as1/radio";
import apiAuthRouter from "./routes/api/auth";
import fs from "fs";
import path from "path";

Expand All @@ -33,13 +35,14 @@ const logger = {
const fastify = Fastify({
...logger,
//For HTTPS in production, please use nginx or whatever
...(WavebreakerConfig.environment == "development" && {
https: {
key: fs.readFileSync(WavebreakerConfig.https.key),
cert: fs.readFileSync(WavebreakerConfig.https.cert),
passphrase: WavebreakerConfig.https.passphrase,
},
}),
...(WavebreakerConfig.environment == "development" &&
WavebreakerConfig.useHttps && {
https: {
key: fs.readFileSync(WavebreakerConfig.https.key),
cert: fs.readFileSync(WavebreakerConfig.https.cert),
passphrase: WavebreakerConfig.https.passphrase,
},
}),
});

fastify.listen(
Expand All @@ -52,16 +55,26 @@ fastify.listen(
}
);

if (WavebreakerConfig.environment == "development")
if (
WavebreakerConfig.environment == "development" &&
WavebreakerConfig.useHttps
)
fastify.register(httpsRedirect); //HTTPS redirect for development, please use nginx or whatever for this in prod

fastify.register(fastifyJwt, {
secret: WavebreakerConfig.token_secret,
});
fastify.register(formbody); //So we can parse requests that use application/x-www-form-urlencoded
fastify.register(fastifyStatic, {
root: path.join(__dirname, "RadioSongs"),
prefix: "/as/asradio/",
});

//Register game endpoints
fastify.register(accountsRouter);
fastify.register(gameplayRouter);
fastify.register(informationRouter);
fastify.register(radioRouter);

//Wavebreaker API
fastify.register(apiAuthRouter);
Loading

0 comments on commit ddd2182

Please sign in to comment.