Server options
There are a few PtsqServer.init
options and this chapter describes them.
Context and CORS
Both context and CORS are described in other chapters.
Root and endpoint
The root
and endpoint
server options are crucial for serving the ptsq
application at the correct endpoint within your server infrastructure.
In scenarios such as using Next.js, where the API resides in the /api
directory within the pages directory, configuring the root
option becomes essential. By specifying the root path using this option, the server understands where to mount the ptsq
application within the server's routing hierarchy. This ensures that requests directed to the appropriate endpoint, such as /api
, are properly routed to the ptsq
application for processing.
In summary, leveraging the root
option is vital for integrating the ptsq
application seamlessly into your server environment, especially when dealing with complex routing configurations or frameworks like Next.js.
PtsqServer.init({
//...,
root: '/api',
});
PtsqServer.init({
//...,
endpoint: '/my-ptsq-server',
});
You can also use the combination of root and endpoint options of course.
PtsqServer.init({
//...,
root: '/api',
endpoint: '/my-ptsq-server',
});
All trailing slashes are removed, so you don't have to care about them.
PtsqServer.init({
//...,
root: '/api/',
endpoint: '/my-ptsq-server/',
});
fetchAPI
The fetchAPI option is for defining which API you will use for the request and response.
PtsqServer.init({
//...,
fetchAPI: {
Request: Request,
Response: Response,
},
});
It's very useful if you are using some integration that has its own request or response object.
Sveltekit example
PtsqServer.init({
//...,
// now ptsq knows, that you are using those fetch request and response objects
fetchAPI: globalThis,
});