Major rewrite

This commit is contained in:
programmingPug
2025-01-14 14:47:10 -05:00
parent 0d7f77b1e3
commit 0f190a3f26
60 changed files with 966 additions and 4872 deletions

View File

@@ -1,4 +0,0 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
"recommendations": ["angular.ng-template"]
}

View File

@@ -1,20 +0,0 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ng serve",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"url": "http://localhost:4200/"
},
{
"name": "ng test",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: test",
"url": "http://localhost:9876/debug.html"
}
]
}

View File

@@ -1,42 +0,0 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
},
{
"type": "npm",
"script": "test",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
}
]
}

25
plant-browser/Dockerfile Normal file
View File

@@ -0,0 +1,25 @@
# Stage 1: Build the Angular application
FROM node:18-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build --prod
# Stage 2: Serve the Angular app using NGINX
FROM nginx:stable-alpine AS runtime
COPY --from=build /app/dist/plant-browser/browser /usr/share/nginx/html
# Remove the default NGINX configuration
RUN rm /etc/nginx/conf.d/default.conf
# Copy custom NGINX configuration
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -40,6 +40,12 @@
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"budgets": [
{
"type": "initial",
@@ -106,4 +112,4 @@
"cli": {
"analytics": "2f66f6d5-a013-454e-b4c4-03f39742aa12"
}
}
}

45
plant-browser/nginx.conf Normal file
View File

@@ -0,0 +1,45 @@
# soilmoisture_client/nginx.conf
worker_processes 1;
events { worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# Docker's internal DNS resolver
resolver 127.0.0.11 valid=10s;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
# Serve Angular App with Client-Side Routing
location / {
try_files $uri $uri/ /index.html;
}
# Proxy API Requests to ASP.NET Core API
location /api/ {
proxy_pass http://soilmoisture_api:80/api/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
# Optional: Increase timeout settings if necessary
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
}
}
}

View File

@@ -2,23 +2,24 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { SoilData } from '../models/soil-data.model';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root'
})
export class SoilDataService {
private apiUrl = 'http://localhost:5284/api/'; // Replace with your actual API endpoint
constructor(private http: HttpClient) {}
private baseUrl = environment.apiUrl;
constructor(private http: HttpClient) { }
getPlants(): Observable<SoilData[]> {
return this.http.get<SoilData[]>(this.apiUrl + 'devices');
return this.http.get<SoilData[]>(`${this.baseUrl}/SoilMoisture`);
}
// Update device nickname
updateNickname(name: string, nickname: string): Observable<any> {
const url = `${this.apiUrl}devices/${encodeURIComponent(name)}/nickname`;
return this.http.put(url, { nickname: nickname });
}
// Update device nickname
updateNickname(name: string, nickname: string): Observable<any> {
const url = `${this.baseUrl}/Device/${encodeURIComponent(name)}/nickname`;
return this.http.put(url, { nickname: nickname });
}
}

View File

@@ -0,0 +1,4 @@
export const environment = {
production: true,
apiUrl: '/api' // Relative path for production (handled by NGINX proxy)
};

View File

@@ -0,0 +1,4 @@
export const environment = {
production: false,
apiUrl: 'http://localhost:8000/api' // For development
};