Vovk.ts client can also be used in a Server Component. To do so, you need to define "prefix" option that indicates absolute URL to the root API endpoint that overrides default relative URL.
1import { get, prefix } from 'vovk';
2
3@prefix('basic')
4export default class BasicController {
5 /**
6 * Return a greeting
7 */
8 @get('greeting', { cors: true })
9 static getHello() {
10 return { greeting: 'Hello world!' };
11 }
12}
1import { get, prefix } from 'vovk';
2
3@prefix('basic')
4export default class BasicController {
5 /**
6 * Return a greeting
7 */
8 @get('greeting', { cors: true })
9 static getHello() {
10 return { greeting: 'Hello world!' };
11 }
12}
1import { get, prefix } from 'vovk';
2
3@prefix('basic')
4export default class BasicController {
5 /**
6 * Return a greeting
7 */
8 @get('greeting', { cors: true })
9 static getHello() {
10 return { greeting: 'Hello world!' };
11 }
12}
1import { get, prefix } from 'vovk';
2
3@prefix('basic')
4export default class BasicController {
5 /**
6 * Return a greeting
7 */
8 @get('greeting', { cors: true })
9 static getHello() {
10 return { greeting: 'Hello world!' };
11 }
12}
1import { BasicController } from 'vovk-client';
2
3export default async function ServerComponentExample() {
4 /*
5 You can pass "prefix" option directly if you don't want to change configuration file.
6 const serverResponse = await BasicController.getHello({
7 prefix: 'http://localhost:3000/api'
8 });
9 */
10 const serverResponse = await BasicController.getHello();
11
12 return <div>{serverResponse.greeting}</div>;
13}
1import { BasicController } from 'vovk-client';
2
3export default async function ServerComponentExample() {
4 /*
5 You can pass "prefix" option directly if you don't want to change configuration file.
6 const serverResponse = await BasicController.getHello({
7 prefix: 'http://localhost:3000/api'
8 });
9 */
10 const serverResponse = await BasicController.getHello();
11
12 return <div>{serverResponse.greeting}</div>;
13}
1import { BasicController } from 'vovk-client';
2
3export default async function ServerComponentExample() {
4 /*
5 You can pass "prefix" option directly if you don't want to change configuration file.
6 const serverResponse = await BasicController.getHello({
7 prefix: 'http://localhost:3000/api'
8 });
9 */
10 const serverResponse = await BasicController.getHello();
11
12 return <div>{serverResponse.greeting}</div>;
13}
1import { BasicController } from 'vovk-client';
2
3export default async function ServerComponentExample() {
4 /*
5 You can pass "prefix" option directly if you don't want to change configuration file.
6 const serverResponse = await BasicController.getHello({
7 prefix: 'http://localhost:3000/api'
8 });
9 */
10 const serverResponse = await BasicController.getHello();
11
12 return <div>{serverResponse.greeting}</div>;
13}
1/** @type {import('vovk').VovkConfig} */
2const config = {
3 // you can use NEXT_PUBLIC_VERCEL_URL env var for preview deployments
4 prefix: process.env.VERCEL_ENV ? `https://vovk-examples.vercel.app/api` : `http://localhost:${process.env.PORT}/api`,
5};
6
7module.exports = config;
1/** @type {import('vovk').VovkConfig} */
2const config = {
3 // you can use NEXT_PUBLIC_VERCEL_URL env var for preview deployments
4 prefix: process.env.VERCEL_ENV ? `https://vovk-examples.vercel.app/api` : `http://localhost:${process.env.PORT}/api`,
5};
6
7module.exports = config;
1/** @type {import('vovk').VovkConfig} */
2const config = {
3 // you can use NEXT_PUBLIC_VERCEL_URL env var for preview deployments
4 prefix: process.env.VERCEL_ENV ? `https://vovk-examples.vercel.app/api` : `http://localhost:${process.env.PORT}/api`,
5};
6
7module.exports = config;
1/** @type {import('vovk').VovkConfig} */
2const config = {
3 // you can use NEXT_PUBLIC_VERCEL_URL env var for preview deployments
4 prefix: process.env.VERCEL_ENV ? `https://vovk-examples.vercel.app/api` : `http://localhost:${process.env.PORT}/api`,
5};
6
7module.exports = config;