Skip to content

route creating cache #70036

Answered by LuWroblewski
LuWroblewski asked this question in Help
Discussion options

You must be logged in to vote

I resolved using on initial lines

export const dynamic = 'force-dynamic';

and his works fine

Complete code:

import { NextResponse } from 'next/server';
import pg from '../../connection';

export const dynamic = 'force-dynamic';

export async function GET() {
  try {
    const latestData = await pg('readings_temperature').select('*').orderBy('created_at', 'desc').first();

    if (!latestData) {
      return NextResponse.json(
        { status: 404, message: 'No data found.' },
        {
          status: 404,
        }
      );
    }

    return NextResponse.json(
      {
        status: 200,
        message: 'Successfully received the latest data.',
        data: latestData,
      },
  …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by LuWroblewski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant