-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to nodejs/webapi project (#39)
- Loading branch information
1 parent
ae307be
commit abad43c
Showing
21 changed files
with
1,208 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
node_modules/ | ||
dist/ | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = [ | ||
{ | ||
rules: { | ||
semi: "error", | ||
"prefer-const": "error" | ||
} | ||
} | ||
]; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.