Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #243

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Improvements #243

wants to merge 11 commits into from

Conversation

ptbrowne
Copy link
Member

Original goal was to separate the dynamic generation out of the API so
that it could be used as a library function.

Then I noticed that there was two different methods to generate and
two different APIs, while the difference seemed small.

I refactored both files to better separate http param handling from
generation, made the generate function more generic (accepting the
mapshaper commands), improved the capacity the ability to style SVGs,
now it is possible to ask for municipalities and countries on the SVG
generation.

Now I wonder why is the api/generate for ? Is it still used, is there
a mean to test it ? @shuaiey would you know ?

@vercel
Copy link

vercel bot commented Feb 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
swiss-maps ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 17, 2023 at 4:15PM (UTC)

draft.format = query.format;
}
const { query } = req;
const options = parseOptions(req, res)!;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parseOptions function ends the response (and if it does it returns undefined). So if options is undefined the handler should exit, otherwise it'll try to write into an already closed response.

);
const { query } = req;
const options = parseOptions(req, res)!;
const { format, shapes, year } = options;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use the non-null assertion operator when there is a reasonable way to avoid. Here check for undefined return value and exit handler.

download: t.union([t.undefined, t.string]),
});

export const parseOptions = (req: NextApiRequest, res: NextApiResponse) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const parseOptions = (req: NextApiRequest, res: NextApiResponse) => {
export const parseOptions = (req: NextApiRequest, res: NextApiResponse): undefined | Options => {

import produce from "immer";
import * as t from "io-ts";
import { NextApiRequest, NextApiResponse } from "next";
import { defaultOptions, Shape } from "src/shared";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { defaultOptions, Shape } from "src/shared";
import { defaultOptions, Options, Shape } from "src/shared";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants