Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions app/api_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const bodyParser = require('body-parser')
const cors = require('cors')
const resources = require('./resources')
const jwtCheck = require('./authentication')

/**
* @swagger
*
Expand Down Expand Up @@ -880,6 +881,47 @@ routes.get('/api/v1/votes', cors(), jwtCheck, resources.v1.votes.get)
routes.post('/api/v1/votes', cors(), jwtCheck, resources.v1.votes.post)
routes.put('/api/v1/votes', cors(), jwtCheck, resources.v1.votes.put)

routes.get('/api/streets/draw', (req, res) => {
const { createCanvas } = require('canvas')

const width = 500
const height = 500

const canvas = createCanvas(width, height)
const context = canvas.getContext('2d')
let radius = canvas.height / 2
context.translate(radius, radius)
radius = radius * 0.9

function drawFace (ctx, radius) {
var grad

ctx.beginPath()
ctx.arc(0, 0, radius, 0, 2 * Math.PI)
ctx.fillStyle = 'white'
ctx.fill()

grad = ctx.createRadialGradient(0, 0, radius * 0.95, 0, 0, radius * 1.05)
grad.addColorStop(0, '#333')
grad.addColorStop(0.5, 'white')
grad.addColorStop(1, '#333')
ctx.strokeStyle = grad
ctx.lineWidth = radius * 0.1
ctx.stroke()

ctx.beginPath()
ctx.arc(0, 0, radius * 0.1, 0, 2 * Math.PI)
ctx.fillStyle = '#333'
ctx.fill()
}

drawFace(context, radius)

// stream out response
res.setHeader('Content-Type', 'image/png')
canvas.pngStream().pipe(res)
})

// Catch all for all broken api paths, direct to 404 response.
routes.get('/api/*', (req, res) => {
res
Expand Down
Loading