Add DATA_PATH env var

This commit is contained in:
TSR Berry 2023-06-21 17:40:33 +02:00
parent 5a270a0eab
commit be3e724868
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2
3 changed files with 20 additions and 10 deletions

View file

@ -21,8 +21,9 @@
This app can be configured using the following environment variables:
| Name | Description | Default value | Notes |
| :------------- | ----------------------------------------------------------------------------------------- | :-----------: | ---------------------------------------------------------------------- |
| :------------- | ----------------------------------------------------------------------------------------- | :-----------: | ------------------------------------------------------------------------------------------------------------ |
| `NODE_ENV` | This should be set to `production` or `development` depending on the current environment. | `""` | |
| `DATA_PATH` | The path to the data directory of this server. | `"data"` | This can either be a relative path or an absolute path. Currently this directory only contains the log file. |
| `SOCKET_PATH` | The path to the unix socket this server should be listening on. | `""` | If this is not empty `HOST` and `PORT` will be ignored. |
| `HOST` | The address this server should be listening on. | `"127.0.0.1"` | |
| `PORT` | The port this server should be using. | `3000` | |

View file

@ -10,6 +10,11 @@ import {
import winston from "winston";
import apiRouter from "./api";
import { errorLogger, requestLogger } from "./middleware";
import { mkdirSync } from "fs";
// Prepare data directory
const dataDirectory = process.env.DATA_PATH ?? "data";
mkdirSync(dataDirectory, { recursive: true });
// Init logger
const loggerInstance = winston.createLogger({
@ -17,7 +22,7 @@ const loggerInstance = winston.createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.File({
filename: `data/ryujinx-ldn-website.log`,
filename: `${dataDirectory}/ryujinx-ldn-website.log`,
}),
],
});

View file

@ -5,7 +5,11 @@ import http from "http";
const server = http.createServer(app);
if (process.env.SOCKET_PATH != null && process.env.SOCKET_PATH.length > 0) {
server.listen(process.env.SOCKET_PATH);
server.listen({
path: process.env.SOCKET_PATH,
readableAll: true,
writableAll: true,
});
}
else {
server.listen(parseInt(env.PORT || "3000"), env.HOST || "127.0.0.1");