forked from andreafspeziale/pokemon-ERC721-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
59 lines (50 loc) · 1.22 KB
/
server.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
/* eslint import/no-dynamic-require: 1 */
const bodyParser = require('body-parser')
const express = require('express')
const data = require('./data/data')
const meta = require('./data/meta')
const config = require('./config/config')
const { truffleBuildPath } = config
const { networkId } = config
const tokenArtifact = require(truffleBuildPath)
const app = express()
app.use(bodyParser.json({ type: 'application/json' }))
app.use(express.static(`${__dirname}/public`))
const router = express.Router()
router.get('/pokemons/:id', (req, res) => {
const { id } = req.params
const pokemon = data[id]
if (pokemon !== undefined) {
res.send(pokemon)
} else {
res.send({
error: 404,
message: 'not found',
})
}
})
router.get('/pokemons/:id/meta', (req, res) => {
const { id } = req.params
const pokemon = meta[id]
if (pokemon !== undefined) {
res.send(pokemon)
} else {
res.send({
error: 404,
message: 'not found',
})
}
})
router.get('/config', (req, res) => {
res.send({
tokenArtifact,
networkId,
})
})
router.get('*', (req, res) => {
res.sendfile('./public/index.html')
})
app.use('/api', router)
app.listen(3000, () => {
console.log('Listening at port 3000... ')
})