From 7256dc9448bcfbd4ece37df650df88b15e58e337 Mon Sep 17 00:00:00 2001 From: Michael Heese Date: Thu, 11 Jun 2020 15:34:17 -0400 Subject: [PATCH 1/6] Removed unneeded nginx.conf --- html/swaggerUI/nginnx.conf | 44 -------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 html/swaggerUI/nginnx.conf diff --git a/html/swaggerUI/nginnx.conf b/html/swaggerUI/nginnx.conf deleted file mode 100644 index 4559b82..0000000 --- a/html/swaggerUI/nginnx.conf +++ /dev/null @@ -1,44 +0,0 @@ -server { - listen 80; - server_name localhost; - - #charset koi8-r; - #access_log /var/log/nginx/host.access.log main; - - location / { - root /usr/share/nginx/html; - index index.html index.htm; - } - - #error_page 404 /404.html; - - # redirect server error pages to the static page /50x.html - # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } - - # proxy the PHP scripts to Apache listening on 127.0.0.1:80 - # - #location ~ \.php$ { - # proxy_pass http://127.0.0.1; - #} - - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 - # - #location ~ \.php$ { - # root html; - # fastcgi_pass 127.0.0.1:9000; - # fastcgi_index index.php; - # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; - # include fastcgi_params; - #} - - # deny access to .htaccess files, if Apache's document root - # concurs with nginx's one - # - #location ~ /\.ht { - # deny all; - #} -} From f1d85113e1644d75d84d4ebec09a6cfecfd5a053 Mon Sep 17 00:00:00 2001 From: Michael Heese Date: Thu, 11 Jun 2020 15:34:51 -0400 Subject: [PATCH 2/6] Removed duplicate api spec --- api-revampd.json | 140 ----------------------------------------------- 1 file changed, 140 deletions(-) delete mode 100644 api-revampd.json diff --git a/api-revampd.json b/api-revampd.json deleted file mode 100644 index 0357e7a..0000000 --- a/api-revampd.json +++ /dev/null @@ -1,140 +0,0 @@ -{ - "openapi": "3.0.2", - "info": { - "description": "This is our Open API Spec descrition for RevAMPD.", - "title": "RevAMPD Open API Spec 3.0", - "version": "1.0" - }, - "servers": [ - { - "url": "https://revampd-api.app.cloud.gov" - } - ], - "components": { - "schemas": { - "Unit": { - "type":"object", - "properties": { - "operatingYear" : { - "type" : "integer", - "format" : "int32" - }, - "unitId" :{ - "type" : "string" - }, - "EPARegion" : { - "type": "integer", - "format" : "int32" - }, - "EPAState":{ - "type": "string" - }, - "facilityName" : { - "type": "string" - }, - "orisCode": { - "type": "integer", - "format": "int32" - }, - "stackId": { - "type": "string" - }, - "operatingStatus": { - "type": "string" - }, - "programCode": { - "type": "string" - }, - "unitType": { - "type": "string" - }, - "primaryFuel": { - "type": "string" - }, - "primaryFuelGroup": { - "type": "string" - }, - "operatingTime": { - "type": "number", - "format": "float" - }, - "grossLoad": { - "type": "number", - "format": "float" - }, - "steamLoad": { - "type": "number", - "format": "float" - }, - "heatInput": { - "type": "number", - "format": "float" - }, - "co2Mass": { - "type": "number", - "format": "float" - }, - "so2Mass": { - "type": "number", - "format": "float" - }, - "noxMass": { - "type": "number", - "format": "float" - } - } - } - }, - "securitySchemes": { - "basicAuth": { - "type": "http", - "scheme": "basic" - }, - "api_key": { - "type":"apiKey", - "name":"api_key", - "in":"query" - } - } - }, - "paths": { - "/units/findByOperatingYear": { - "get": { - "description": "Returns annual unit data", - "parameters": [ - { - "name": "operatingYear", - "in": "query", - "description": "Operating year", - "required": true, - "schema": { - "type": "integer", - "format": "int32" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Unit" - } - } - } - } - }, - "204": { - "description": "No units were found" - }, - "400": { - "description": "A valid operating year is required" - } - } - } - } - } -} \ No newline at end of file From 2beac45a5d0cd48219c9c9fe167d061a88998fda Mon Sep 17 00:00:00 2001 From: Michael Heese Date: Thu, 11 Jun 2020 15:37:26 -0400 Subject: [PATCH 3/6] Serving API spec from api backend --- src/api-spec/api-revampd.json | 135 ++++++++++++++++++++++++++++++++++ src/main.go | 18 +++-- 2 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 src/api-spec/api-revampd.json diff --git a/src/api-spec/api-revampd.json b/src/api-spec/api-revampd.json new file mode 100644 index 0000000..efb3a14 --- /dev/null +++ b/src/api-spec/api-revampd.json @@ -0,0 +1,135 @@ +{ + "openapi": "3.0.2", + "info": { + "description": "This is our Open API Spec descrition for RevAMPD.", + "title": "RevAMPD Open API Spec 3.0", + "version": "1.0" + }, + "components": { + "schemas": { + "Unit": { + "type":"object", + "properties": { + "operatingYear" : { + "type" : "integer", + "format" : "int32" + }, + "unitId" :{ + "type" : "string" + }, + "EPARegion" : { + "type": "integer", + "format" : "int32" + }, + "EPAState":{ + "type": "string" + }, + "facilityName" : { + "type": "string" + }, + "orisCode": { + "type": "integer", + "format": "int32" + }, + "stackId": { + "type": "string" + }, + "operatingStatus": { + "type": "string" + }, + "programCode": { + "type": "string" + }, + "unitType": { + "type": "string" + }, + "primaryFuel": { + "type": "string" + }, + "primaryFuelGroup": { + "type": "string" + }, + "operatingTime": { + "type": "number", + "format": "float" + }, + "grossLoad": { + "type": "number", + "format": "float" + }, + "steamLoad": { + "type": "number", + "format": "float" + }, + "heatInput": { + "type": "number", + "format": "float" + }, + "co2Mass": { + "type": "number", + "format": "float" + }, + "so2Mass": { + "type": "number", + "format": "float" + }, + "noxMass": { + "type": "number", + "format": "float" + } + } + } + }, + "securitySchemes": { + "basicAuth": { + "type": "http", + "scheme": "basic" + }, + "api_key": { + "type":"apiKey", + "name":"api_key", + "in":"query" + } + } + }, + "paths": { + "/units/findByOperatingYear": { + "get": { + "description": "Returns annual unit data", + "parameters": [ + { + "name": "operatingYear", + "in": "query", + "description": "Operating year", + "required": true, + "schema": { + "type": "integer", + "format": "int32" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Unit" + } + } + } + } + }, + "204": { + "description": "No units were found" + }, + "400": { + "description": "A valid operating year is required" + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main.go b/src/main.go index b9bc72c..0ee0080 100644 --- a/src/main.go +++ b/src/main.go @@ -60,12 +60,15 @@ func findUnitsByOperatingYear(w http.ResponseWriter, r *http.Request, dbService } } -//Allows all sites to access the API. This can be fine tuned -func enableCors(w *http.ResponseWriter) { - (*w).Header().Set("Access-Control-Allow-Origin", "*") +//Enable Cross-Origin Resource Sharing (CORS) +func enableCors(handler http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + (w).Header().Set("Access-Control-Allow-Origin", "*") + handler.ServeHTTP(w, r) + }) } -func main() { +func main() { dbService, err := CreateDatabaseService() if err != nil { @@ -73,10 +76,13 @@ func main() { } http.HandleFunc("/units/findByOperatingYear", func(w http.ResponseWriter, r *http.Request) { - enableCors(&w) findUnitsByOperatingYear(w, r, dbService) }) + fs := http.FileServer(http.Dir("./api-spec")) + http.Handle("/swagger/", http.StripPrefix("/swagger", fs)) + log.Debug("Starting revAMPD API backend, listening on port " + os.Getenv("PORT")) - http.ListenAndServe(":"+os.Getenv("PORT"), nil) + //Enable CORS at the server level + http.ListenAndServe(":"+os.Getenv("PORT"), enableCors(http.DefaultServeMux)) } From 4e678568166844735db35920c70950dd394a1245 Mon Sep 17 00:00:00 2001 From: Michael Heese Date: Thu, 11 Jun 2020 15:38:32 -0400 Subject: [PATCH 4/6] Moved API spec to api backend --- html/swaggerUI/api-revampd.json | 140 -------------------------------- 1 file changed, 140 deletions(-) delete mode 100644 html/swaggerUI/api-revampd.json diff --git a/html/swaggerUI/api-revampd.json b/html/swaggerUI/api-revampd.json deleted file mode 100644 index 06b565c..0000000 --- a/html/swaggerUI/api-revampd.json +++ /dev/null @@ -1,140 +0,0 @@ -{ - "openapi": "3.0.2", - "info": { - "description": "This is our Open API Spec descrition for RevAMPD.", - "title": "RevAMPD Open API Spec 3.0", - "version": "1.0" - }, - "servers": [ - { - "url": "http://localhost:8080/" - } - ], - "components": { - "schemas": { - "Unit": { - "type":"object", - "properties": { - "operatingYear" : { - "type" : "integer", - "format" : "int32" - }, - "unitId" :{ - "type" : "string" - }, - "EPARegion" : { - "type": "integer", - "format" : "int32" - }, - "EPAState":{ - "type": "string" - }, - "facilityName" : { - "type": "string" - }, - "orisCode": { - "type": "integer", - "format": "int32" - }, - "stackId": { - "type": "string" - }, - "operatingStatus": { - "type": "string" - }, - "programCode": { - "type": "string" - }, - "unitType": { - "type": "string" - }, - "primaryFuel": { - "type": "string" - }, - "primaryFuelGroup": { - "type": "string" - }, - "operatingTime": { - "type": "number", - "format": "float" - }, - "grossLoad": { - "type": "number", - "format": "float" - }, - "steamLoad": { - "type": "number", - "format": "float" - }, - "heatInput": { - "type": "number", - "format": "float" - }, - "co2Mass": { - "type": "number", - "format": "float" - }, - "so2Mass": { - "type": "number", - "format": "float" - }, - "noxMass": { - "type": "number", - "format": "float" - } - } - } - }, - "securitySchemes": { - "basicAuth": { - "type": "http", - "scheme": "basic" - }, - "api_key": { - "type":"apiKey", - "name":"api_key", - "in":"query" - } - } - }, - "paths": { - "/units/findByOperatingYear": { - "get": { - "description": "Returns annual unit data", - "parameters": [ - { - "name": "operatingYear", - "in": "query", - "description": "Operating year", - "required": true, - "schema": { - "type": "integer", - "format": "int32" - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Unit" - } - } - } - } - }, - "204": { - "description": "No units were found" - }, - "400": { - "description": "A valid operating year is required" - } - } - } - } - } -} \ No newline at end of file From 8c74e14b3c9675a60bdfde32f932cb899b5d2147 Mon Sep 17 00:00:00 2001 From: Michael Heese Date: Thu, 11 Jun 2020 15:39:16 -0400 Subject: [PATCH 5/6] Added constant for API_URL --- html/swaggerUI/index.html | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/html/swaggerUI/index.html b/html/swaggerUI/index.html index fddb308..063d63f 100644 --- a/html/swaggerUI/index.html +++ b/html/swaggerUI/index.html @@ -37,9 +37,17 @@ + @@ -329,4 +329,4 @@

Some Links

- + \ No newline at end of file diff --git a/html/src/app.js b/html/src/app.js index f889e14..45cf3d8 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -14,7 +14,7 @@ function buildUrl (url) { }, methods: { getPosts(section) { - let url = apiUrl+section+"?operatingYear=2018"; + let url = API_URL+section+"?operatingYear=2018"; console.log(url); axios.get(url).then(response => { console.log(response.data);