change port of graphiql? #1320
-
i want to change the port from http://localhost:4000/graphql to http://localhost:3000/api couldn't find it in docs. how to change that? the reason to change it is i don't have to explicitly remember even though it outputs the url in console. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
Hi @deadcoder0904 , Also, do you wish to change only GraphiQL port? or the entire Yoga server/listener port? |
Beta Was this translation helpful? Give feedback.
-
so i did try a couple of different methods & none worked. i don't think 1. use
|
Beta Was this translation helpful? Give feedback.
-
found the answer. it was on the last line on migration but definitely not obvious. just had to add const yoga = createServer({
schema,
context: async ({ req }): Promise<GraphQLContext> => ({
admin: req.session.admin,
origin: getRequestOrigin(req),
prisma,
}),
plugins: [useApolloServerErrors()],
})
const isAdminMiddleware = (req: NextIronRequest, res: NextApiResponse, next: NextHandler) => {
if (req.session.admin) {
req.admin = req.session.admin
}
return next()
}
export default handler().use(isAdminMiddleware).use('/api', yoga) |
Beta Was this translation helpful? Give feedback.
-
for export default handler()
.use(isAdminMiddleware)
.all('/api', yoga, () => {
console.log(`💡 🧘 Yoga - Running GraphQL Server at http://localhost:3000/api`)
}) |
Beta Was this translation helpful? Give feedback.
found the answer. it was on the last line on migration but definitely not obvious.
just had to add
.use('/api', yoga)
to make it work on the same port: