Enforce trailing slashes on API paths

This ensures that the Next.js app works consistently both when running in dev mode as well as when it has been exported to static HTML/JS.
This commit is contained in:
David Stotijn
2020-09-27 11:33:10 +02:00
parent adba24b78f
commit 91947b9ffa
3 changed files with 6 additions and 6 deletions

View File

@ -6,8 +6,8 @@ module.exports = withCSS({
async rewrites() {
return [
{
source: "/api/:path",
destination: "http://localhost:8080/api/:path", // Matched parameters can be used in the destination
source: "/api/:path/",
destination: "http://localhost:8080/api/:path/",
},
];
},

View File

@ -8,7 +8,7 @@ function createApolloClient() {
return new ApolloClient({
ssrMode: typeof window === "undefined",
link: new HttpLink({
uri: "/api/graphql",
uri: "/api/graphql/",
}),
cache: new InMemoryCache({
typePolicies: {

View File

@ -81,11 +81,11 @@ func main() {
hostname, _ := os.Hostname()
host, _, _ := net.SplitHostPort(req.Host)
return strings.EqualFold(host, hostname) || (req.Host == "hetty.proxy" || req.Host == "localhost:8080")
}).Subrouter()
}).Subrouter().StrictSlash(true)
// GraphQL server.
adminRouter.Path("/api/playground").Handler(playground.Handler("GraphQL Playground", "/api/graphql"))
adminRouter.Path("/api/graphql").Handler(handler.NewDefaultServer(api.NewExecutableSchema(api.Config{Resolvers: &api.Resolver{
adminRouter.Path("/api/playground/").Handler(playground.Handler("GraphQL Playground", "/api/graphql/"))
adminRouter.Path("/api/graphql/").Handler(handler.NewDefaultServer(api.NewExecutableSchema(api.Config{Resolvers: &api.Resolver{
RequestLogService: reqLogService,
}})))