-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: main
Are you sure you want to change the base?
Improvements #243
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
fc3e062
to
0d097a2
Compare
Types is still not super good though
0d097a2
to
37a7091
Compare
draft.format = query.format; | ||
} | ||
const { query } = req; | ||
const options = parseOptions(req, res)!; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { defaultOptions, Shape } from "src/shared"; | |
import { defaultOptions, Options, Shape } from "src/shared"; |
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
andtwo 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 therea mean to test it ? @shuaiey would you know ?