Skip to content

Commit

Permalink
fix: support localhost urls (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
simoneb committed Mar 2, 2023
1 parent a68be05 commit a0bc973
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/autocannon-ui-backend/routes/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import execute from '../services/autocannon.js'

const schema = {
body: S.object()
.prop('url', S.string().format('url').required())
.prop('url', S.string().format('uri').required())
.prop('connections', S.integer().default(10))
.prop('duration', S.anyOf([S.number(), S.string()]).default(10))
.prop('pipelining', S.integer().default(1))
Expand Down
16 changes: 15 additions & 1 deletion packages/autocannon-ui-backend/test/unit/routes/execute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Fastify from 'fastify'
import index from '../../../index.js'

t.test('execute', async t => {
t.test('returns 404 if url is not valid', async t => {
t.test('returns 400 if url is not valid', async t => {
const fastify = Fastify().register(index)

const response = await fastify.inject({
Expand All @@ -17,4 +17,18 @@ t.test('execute', async t => {

t.same(response.statusCode, 400)
})

t.test('supports localhost urls with port', async t => {
const fastify = Fastify().register(index)

const response = await fastify.inject({
url: '/api/execute',
method: 'POST',
body: {
url: 'http://localhost:3000'
}
})

t.same(response.statusCode, 200)
})
})

0 comments on commit a0bc973

Please sign in to comment.