I need to call the function
moveUpB
from inside the
response.status(200).send
part and I think that part is json, but I don't know that much about json. The
response.status
and
moveUpB
are inside the
handleMove
function. I have been trying everything to get it to work for weeks and I still have no idea. The rest of my code is there in case it is needed. I need to send data to a different website or server or something, and the
response.status
sends it. My
move
commands need to be in
handlemove
and if I try to use
move
commands above the
response.status
, they only execute once. If I try to use it below the
response.status
, it gives me an error. This makes me think that my
move
commands need to be called from inside the
response.status
part. I hope someone here can help me.
const express = require('express')
const PORT = process.env.PORT || 3000
const app = express()
app.use(bodyParser.json())
app.get('/', handleIndex)
app.post('/start', handleStart)
app.post('/move', handleMove)
app.post('/end', handleEnd)
app.listen(PORT, () => console.log(`Battlesnake Server listening at http://127.0.0.1:${PORT}`))
function handleIndex(request, response) {
var battlesnakeInfo = {
apiversion: '1',
author: '',
color: '#1c607d',
head: 'caffeine',
tail: 'leaf'
}
response.status(200).json(battlesnakeInfo)
}
function handleStart(request, response) {
var gameData = request.body
console.log('START')
response.status(200).send('ok')
}
function handleMove(request, response) {
var gameData = request.body
What I have tried:
Everything I could think of and nothing worked.