Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
FROM node

ENV PERSISTENCE_LOCATION=/data
EXPOSE 3000

RUN groupadd osweather && useradd --no-log-init -m -g osweather osweather
RUN groupadd osweather && useradd --no-log-init -m -g osweather osweather && \
mkdir /data && \
chown osweather:osweather /data

USER osweather
VOLUME /data

ADD --chown=osweather:osweather . weather

Expand Down
2 changes: 1 addition & 1 deletion routes/geocoders/Geocoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CodedError, ErrorCode } from "../../errors";

export abstract class Geocoder {

private static cacheFile: string = __dirname + "/../../../geocoderCache.json";
private static cacheFile: string = (process.env.PERSISTENCE_LOCATION || __dirname + "/../../..") + "/geocoderCache.json";

private cache: Map<string, GeoCoordinates>;

Expand Down
11 changes: 6 additions & 5 deletions routes/weatherProviders/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const captureWUStream = async function( req: express.Request, res: expres
};

export default class LocalWeatherProvider extends WeatherProvider {

public static observationsFile: string = ( process.env.PERSISTENCE_LOCATION ? process.env.PERSISTENCE_LOCATION + "/observations.json" : "observations.json");
Copy link

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Construct file paths using Node’s path.join or path.resolve instead of manual string concatenation to ensure correct cross-platform behavior.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback path "observations.json" is relative to the current working directory and may not resolve as expected; consider using __dirname or a configured base path for consistency.

Copilot uses AI. Check for mistakes.

public async getWeatherData( coordinates: GeoCoordinates ): Promise< WeatherData > {
queue = queue.filter( obs => moment().unix() - obs.timestamp < 24*60*60 );

Expand Down Expand Up @@ -126,16 +127,16 @@ export default class LocalWeatherProvider extends WeatherProvider {
function saveQueue() {
queue = queue.filter( obs => moment().unix() - obs.timestamp < 24*60*60 );
try {
fs.writeFileSync( "observations.json" , JSON.stringify( queue ), "utf8" );
fs.writeFileSync( LocalWeatherProvider.observationsFile , JSON.stringify( queue ), "utf8" );
} catch ( err ) {
console.error( "Error saving historical observations to local storage.", err );
}
}

if ( process.env.WEATHER_PROVIDER === "local" && process.env.LOCAL_PERSISTENCE ) {
if ( fs.existsSync( "observations.json" ) ) {
if ( process.env.WEATHER_PROVIDER === "local" && (process.env.LOCAL_PERSISTENCE || process.env.PERSISTENCE_LOCATION) ) {
if ( fs.existsSync( LocalWeatherProvider.observationsFile ) ) {
try {
queue = JSON.parse( fs.readFileSync( "observations.json", "utf8" ) );
queue = JSON.parse( fs.readFileSync( LocalWeatherProvider.observationsFile, "utf8" ) );
queue = queue.filter( obs => moment().unix() - obs.timestamp < 24*60*60 );
} catch ( err ) {
console.error( "Error reading historical observations from local storage.", err );
Expand Down