forked from checkly/danube-store
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change books get endpoint to prefer lotr as requested from FR-FE7118
- Loading branch information
Showing
1 changed file
with
67 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,67 @@ | ||
require('./tracing') | ||
const fs = require('fs') | ||
const express = require('express') | ||
const cors = require('cors') | ||
const { v4: uuidv4 } = require('uuid'); | ||
const morgan = require('morgan') | ||
|
||
const app = express() | ||
const port = process.env.PORT || 5000 | ||
|
||
app.use(express.json()) | ||
app.use(cors()) | ||
app.use(morgan('tiny')) | ||
|
||
app.get('/404', (req, res) => { | ||
res.status(404).sendFile(__dirname + '/404.html') | ||
}) | ||
|
||
app.use(express.static(__dirname + '/vue/dist')) | ||
|
||
app.get('/api/books/list', (req, res) => { | ||
if (fs.existsSync('downtime.json')) { | ||
res.status(500).send() | ||
} else { | ||
const rawData = fs.readFileSync('books.json') | ||
const books = JSON.parse(rawData) | ||
res.status(200).json(books) | ||
} | ||
}) | ||
|
||
app.get('/api/books/:id', (req, res) => { | ||
const rawData = fs.readFileSync('books.json') | ||
const books = JSON.parse(rawData) | ||
var arrayFound = books.filter(function(item) { | ||
return item.id == req.params.id; | ||
}); | ||
res.status(200).json(arrayFound[0]) | ||
}) | ||
|
||
app.get('/api/users/login', (req, res) => { | ||
res.status(200).json({ | ||
message: 'Login successful', | ||
token: uuidv4(), | ||
name: 'Danube' | ||
}) | ||
}) | ||
|
||
|
||
app.post('/api/toggle', (req, res) => { | ||
if (fs.existsSync('downtime.json')) { | ||
fs.unlinkSync('downtime.json') | ||
res.status(200).send() | ||
} else { | ||
fs.writeFileSync('downtime.json', '{}') | ||
res.status(200).send() | ||
} | ||
}) | ||
|
||
app.get(/.*/, (req,res) => { | ||
res.sendFile(__dirname + '/vue/dist/index.html') | ||
}) | ||
|
||
app.listen(port, () => console.log(`Example app listening on port ${port}!`)) | ||
require("./tracing"); | ||
const fs = require("fs"); | ||
const express = require("express"); | ||
const cors = require("cors"); | ||
const { v4: uuidv4 } = require("uuid"); | ||
const morgan = require("morgan"); | ||
|
||
const app = express(); | ||
const port = process.env.PORT || 5000; | ||
|
||
app.use(express.json()); | ||
app.use(cors()); | ||
app.use(morgan("tiny")); | ||
|
||
app.get("/404", (req, res) => { | ||
res.status(404).sendFile(__dirname + "/404.html"); | ||
}); | ||
|
||
app.use(express.static(__dirname + "/vue/dist")); | ||
|
||
app.get("/api/books", (req, res) => { | ||
if (fs.existsSync("downtime.json")) { | ||
res.status(500).send(); | ||
} else { | ||
const rawData = fs.readFileSync("books.json"); | ||
const books = JSON.parse(rawData); | ||
|
||
if (books[0].name !== "Lord of the Rings") { | ||
res.status(500).send(); | ||
} else { | ||
res.status(200).json(books); | ||
} | ||
} | ||
}); | ||
|
||
app.get("/api/books/:id", (req, res) => { | ||
const rawData = fs.readFileSync("books.json"); | ||
const books = JSON.parse(rawData); | ||
var arrayFound = books.filter(function (item) { | ||
return item.id == req.params.id; | ||
}); | ||
res.status(200).json(arrayFound[0]); | ||
}); | ||
|
||
app.get("/api/users/login", (req, res) => { | ||
res.status(200).json({ | ||
message: "Login successful", | ||
token: uuidv4(), | ||
name: "Danube", | ||
}); | ||
}); | ||
|
||
app.post("/api/toggle", (req, res) => { | ||
if (fs.existsSync("downtime.json")) { | ||
fs.unlinkSync("downtime.json"); | ||
res.status(200).send(); | ||
} else { | ||
fs.writeFileSync("downtime.json", "{}"); | ||
res.status(200).send(); | ||
} | ||
}); | ||
|
||
app.get(/.*/, (req, res) => { | ||
res.sendFile(__dirname + "/vue/dist/index.html"); | ||
}); | ||
|
||
app.listen(port, () => console.log(`Example app listening on port ${port}!`)); |