Skip to content

Commit

Permalink
Merge pull request #96 from Kanahiro/fix/hono-quick
Browse files Browse the repository at this point in the history
Fix/hono quick
  • Loading branch information
Kanahiro authored Aug 2, 2024
2 parents 1f79fc6 + a0aecf3 commit 1d8d24b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "chiitiler",
"version": "1.12.0",
"version": "1.12.1",
"description": "Tiny map rendering server for MapLibre Style Spec",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/server/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('initServer', () => {
const res2 = await app.request(
'/clip.gif?bbox=0,1,2,3&url=file://localdata/style.json',
);
expect(res2.status).toBe(404); // invalid format will not be handled in /clip
expect(res2.status).toBe(400); // invalid format will not be handled in /clip

const res3 = await app.request(
'clip.png?bbox=0,0,0,0&url=file://localdata/style.json',
Expand Down
12 changes: 7 additions & 5 deletions src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hono } from 'hono';
import { Hono } from 'hono/quick';
import { serve } from '@hono/node-server';
import {
type StyleSpecification,
Expand Down Expand Up @@ -117,9 +117,10 @@ function initServer(options: InitServerOptions) {
});

const clip = new Hono()
.get('/:filename{clip\\.png|webp|jpeg|jpg$}', async (c) => {
.get('/:filename_ext', async (c) => {
// path params
const [_, ext] = c.req.param('filename').split('.');
const [filename, ext] = c.req.param('filename_ext').split('.');
if (filename !== 'clip') return c.body('not found', 404);
if (!isSupportedFormat(ext)) return c.body('invalid format', 400);

// query params
Expand Down Expand Up @@ -150,14 +151,15 @@ function initServer(options: InitServerOptions) {
return c.body('failed to render bbox', 400);
}
})
.post('/:filename{clip\\.png|webp|jpeg|jpg$}', async (c) => {
.post('/:filename_ext', async (c) => {
// body
const { style } = await c.req.json();
if (!isValidStylejson(style))
return c.body('invalid stylejson', 400);

// path params
const [_, ext] = c.req.param('filename').split('.');
const [filename, ext] = c.req.param('filename_ext').split('.');
if (filename !== 'clip') return c.body('not found', 404);
if (!isSupportedFormat(ext)) return c.body('invalid format', 400);

// query params
Expand Down

0 comments on commit 1d8d24b

Please sign in to comment.