-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestSidecar.js
76 lines (63 loc) · 1.89 KB
/
testSidecar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const express = require('express')
const faker = require('faker/locale/zh_CN')
const logger = require('morgan')
const services = require('./service')
const app = express()
// let count = 100
// const books = new Array(count)
// while (count > 0) {
// books[count] = {
// id: count,
// name: faker.name.title(),
// authorId: parseInt(Math.random() * 100) + 1,
// publishDate: faker.date.past().toLocaleString(),
// des: faker.lorem.paragraph(),
// ISBN: `ISBN 000-0000-00-0`
// }
// count --
// }
// app.use(logger('combined'))
// app.get('/health', (req, res) => {
// res.json({
// status: 'UP'
// })
// })
// app.get('/book/:id', (req, res, next) => {
// const id = parseInt(req.params.id)
// if(isNaN(id)){
// next()
// }
// res.json(books[id])
// })
// app.get('/book/:bookId/author', (req, res, next) => {
// const bookId = parseInt(req.params.bookId)
// if(isNaN(bookId)){
// next()
// }
// const book = books[bookId]
// if(book) {
// let uid = book.authorId
// services.getUserById(uid).then((user) => {
// if(user.id) {
// res.json(user)
// }else{
// throw new Error("user not found")
// }
// }).catch((error)=> next(error))
// }
// })
// app.get('/books', (req, res, next) => {
// const uid = req.query.uid
// res.json(books.filter((book)=>book.authorId == uid))
// })
// app.get('/config', (req, res) => {
// services.getConfig('user-service').then((config) => {
// res.json(config)
// }).catch((e)=> next(e))
// })
// app.use((error, req, res, next) => {
// const status = 500 || error.status;
// res.status(status)
// res.json({status, message: 'service error'})
// })
// app.listen(3000, () => console.log("express-application listening on 3000"))