Skip to content

Commit

Permalink
Updates to nodejs/webapi project (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliamuiruri4 authored Jul 11, 2024
1 parent ae307be commit abad43c
Show file tree
Hide file tree
Showing 21 changed files with 1,208 additions and 459 deletions.
6 changes: 3 additions & 3 deletions docs/api-center-analyzer-integration-nodejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ You can analyze your API documents using Visual Studio Code (Standalone) or Azur

![Standalone API Analysis - analysis result](./images/api-center-analyzer-integration-nodejs-06.png)

1. Open `nodejs/webapi/server.js`,
1. Open `nodejs/webapi/app.js`,
- Find the following code block:

```javascript
// route to serve basic/ improved JSON, Set up Swagger UI and redirect
// route to serve basic/ improved JSON
app.get("/api-docs/swagger.json", (req, res) => {
// res.send(swaggerSpecs.improved);
res.send(swaggerSpecs.basic);
Expand All @@ -60,7 +60,7 @@ You can analyze your API documents using Visual Studio Code (Standalone) or Azur
- Comment out the line `res.send(swaggerSpecs.basic);`

```javascript
// route to serve basic/ improved JSON, Set up Swagger UI and redirect
// route to serve basic/ improved JSON
app.get("/api-docs/swagger.json", (req, res) => {
res.send(swaggerSpecs.improved);
// res.send(swaggerSpecs.basic);
Expand Down
Binary file modified docs/images/api-center-analyzer-integration-nodejs-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/api-center-analyzer-integration-nodejs-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/api-center-analyzer-integration-nodejs-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/api-center-analyzer-integration-nodejs-07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/api-center-analyzer-integration-nodejs-08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/api-center-analyzer-integration-nodejs-09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions infra/core/host/appservice.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ param linuxFxVersion string = runtimeNameAndVersion
param minimumElasticInstanceCount int = -1
param numberOfWorkers int = -1
param scmDoBuildDuringDeployment bool = false
param websitenodedefaultversion string = '~20'
param use32BitWorkerProcess bool = false
param ftpsState string = 'FtpsOnly'
param healthCheckPath string = ''
Expand Down Expand Up @@ -96,6 +97,7 @@ module configAppSettings 'appservice-appsettings.bicep' = {
{
SCM_DO_BUILD_DURING_DEPLOYMENT: string(scmDoBuildDuringDeployment)
ENABLE_ORYX_BUILD: string(enableOryxBuild)
WEBSITE_NODE_DEFAULT_VERSION: string(websitenodedefaultversion)
},
runtimeName == 'python' && appCommandLine == '' ? { PYTHON_ENABLE_GUNICORN_MULTIWORKERS: 'true'} : {},
!empty(applicationInsightsName) ? { APPLICATIONINSIGHTS_CONNECTION_STRING: applicationInsights.properties.ConnectionString } : {},
Expand Down
Empty file removed nodejs/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion nodejs/webapi/. eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/
dist/
bin/
72 changes: 72 additions & 0 deletions nodejs/webapi/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const express = require("express");
const { setupSwaggerUi, swaggerSpecs } = require("./routes/openapiservice");
const weatherRouter = require("./routes/weather");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");

// JSDoc comments for api endpoints
/**
* @swagger
* /weatherforecast:
* get:
* description: Use to request weather data
* operationId: getWeatherData
* tags:
* - Weather
* responses:
* 200:
* description: A successful response
* content:
* application/json:
* schema:
* type: array
* items:
* type: object
* properties:
* date:
* type: string
* format: date
* description: Date of the weather forecast
* example: '2024-06-05'
* temperatureC:
* type: integer
* description: Temperature in Celsius
* example: 51
* summary:
* type: string
* description: Weather summary
* example: Cool
* temperatureF:
* type: integer
* description: Temperature in Fahrenheit
* example: 123
*/

const app = express();

app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

app.use("/weatherforecast", weatherRouter);

if (process.env.NODE_ENV !== 'production') {
// route to serve basic/ improved JSON
app.get("/api-docs/swagger.json", (req, res) => {
res.send(swaggerSpecs.basic);
// res.send(swaggerSpecs.improved);

});

setupSwaggerUi(app, swaggerSpecs.basic, "/api-docs/swagger");
// setupSwaggerUi(app, swaggerSpecs.improved, "/api-docs/swagger");
}

app.get("/", (req, res) => {
res.redirect("/weatherforecast");
});

module.exports = app;
89 changes: 89 additions & 0 deletions nodejs/webapi/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require("../app");
var debug = require("debug")("webapi:server");
var http = require("http");

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || "3030");
app.set("port", port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on("error", onError);
server.on("listening", onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}


/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== "listen") {
throw error;
}

var bind = typeof port === "string" ? "Pipe " + port : "Port " + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case "EACCES":
console.error(bind + " requires elevated privileges");
process.exit(1);
break;
case "EADDRINUSE":
console.error(bind + " is already in use");
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
debug("Listening on " + bind);
}

// module.exports = { port };
6 changes: 0 additions & 6 deletions nodejs/webapi/config.js

This file was deleted.

8 changes: 8 additions & 0 deletions nodejs/webapi/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = [
{
rules: {
semi: "error",
"prefer-const": "error"
}
}
];
10 changes: 0 additions & 10 deletions nodejs/webapi/eslint.config.mjs

This file was deleted.

Loading

0 comments on commit abad43c

Please sign in to comment.