Not seeing scheduled badge next to my scehdule function

I am trying to create a scheduled function in netlify for my site: 925f9b60-a694-47a1-b41a-d34bb0c156f7

I am facing two issues:

  1. I have not been able to uccessfully set up netlify dev locally. Everytime i run netlify functions:serve, the inital logs load fine, and then i get
    Loaded function api
    Request from ::1: GET /api/users
    Response with status 404 in 6 ms.
    Request from ::1: OPTIONS /api/graphql
    Response with status 404 in 11 ms.

I get a 404, for all routes on this.
I used to test my opening a post locally →
app.listen(3000, () => console.log(‘Local app listening on port 3000!’));

But it doesnt help here for testing scheduled functions

  1. I deployed this to my main deploy (not branch deploy) as per the documentation. I see the file in my functions, but not scheduled badge

This is my scheduled.ts file location in my functions folder

import type { Handler, HandlerEvent, HandlerContext } from "@netlify/functions";
import { schedule } from "@netlify/functions";
import { LoggerInstance } from "../src/helpers/logger";

const sendReviewEmails: Handler = async (event: HandlerEvent, context: HandlerContext) => {
    LoggerInstance.debug('Scehdule job')

    return {
        statusCode: 200,
    };
};
const handler = schedule("@hourly", sendReviewEmails)
export { handler };

Please help me debug this. Not sure what i am missing.

Is this the code in your app? If yes, that’s probably not gonna work.

Have you setup the redirect as explained here: Express on Netlify | Netlify Docs?

Even if you did that, I am not sure if that would be used when you use functions:serve. You should simply use netlify dev instead.

Regarding the scheduled functions issue, is that the exact piece of code that you’ve currently deployed? If yes, that should work and it would have to be escalated to the devs.

The app.listen() code is in another file - apptest.ts → which i use for testing locally.

My redirects are configured according to the doc and it works fine in the netlify deployments. Just doesnt work in the local setup using ‘netlify dev’ or netlify functions:serve is failing with the same 404 error. I want this to work correctly to reduce my testing time for scheduled functions.
This is my netlify.toml file


[build]
    functions = "dist/functions"

[[redirects]]
    to="/.netlify/functions/api/:splat"
    from="/api/*"
    status=200

Regarding the scheduled function: Yes that is the exact piece of code for scheduled function. Please escalate it if necessary.

The CLI issue would be not possible to debug without seeing your repo. I have the same setup in several projects of mine and I don’t have an issue with those.

I have escalated the Scheduled Functions error to the devs and will let you know once we hear back from the team.

I dont think i can share my repo, but can share info about it. Its a ts express node app, with this structure, with api.ts in functions folder being the starting point

And api.ts has this code in it:

import express from 'express';
import serverless from 'serverless-http';
import bodyParser from 'body-parser';
import cors from 'cors';
import cookieParser from 'cookie-parser';
import 'dotenv/config';
import { expressMiddleware } from '@apollo/server/express4';
import { LoggerInstance } from "../src/helpers/logger";
import userRouter from '../src/routes/users';
import experiencesRouter from '../src/routes/experiences';
import authRouter from '../src/routes/auth';
import mediaRouter from '../src/routes/media';
import apolloServer, { isAdminRequest } from '../src/graphqlResolvers/apolloServerInstance';

LoggerInstance.debug('api.ts application starting');
apolloServer.start().then(() => {
  const router = express.Router();
  const jsonParser = bodyParser.json({
    limit: '10mb'
  });
  const urlEncoded = bodyParser.urlencoded({limit: '10mb', extended: true});
  LoggerInstance.debug('api.ts apollo server starting');
  // middelwares
  app.use((req, res, next) => {
    // res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Credentials", "true");
    next();
  });
  app.use(jsonParser);
  app.use(urlEncoded);

  const allowedOrigins = process.env.ALLOWED_ORIGINS.split(', ').map(origin=>origin);
  LoggerInstance.debug(allowedOrigins);
  const corsUsage = cors({
    origin: allowedOrigins
  });
  app.use(corsUsage);

  app.use(cookieParser());

  // routes
  app.use('/api', router);
  app.use('/api/users', userRouter);
  app.use('/api/experiences', experiencesRouter);
  app.use('/api/auth', authRouter);
  app.use('/api/media', mediaRouter);

  // Graphql
  // Specify the path where we'd like to mount our server
  app.use('/api/graphql', corsUsage, jsonParser, expressMiddleware(apolloServer, {
    context: async ({ req, res }) => (
      {
        admin: await isAdminRequest(req)
      })
  }));
  LoggerInstance.debug('api.ts Initialization complete');
});

export const app = express()
module.exports.handler = serverless(app);

The rest of the code are routes, its controllers and the implementation.

Any thoughts about what could be going wrong with the setup with this info?

And thanks for forwarding the scheduled issue to the devs

Shouldn’t these be app.get() or similar?

app.use() is for setting middlewares: Express routing (expressjs.com)

Apart from that, hard to say without checking this locally.

Regarding the scheduled function issue, could you try changing the last line to:

export const { handler }

or declare the schedule in netlify.toml?

Just trying to narrow down the issue.

Hey sorry for the late reply, had to deal with a few other high prii things.

  1. Regarding app.use - the.get, .post are used inside the router like userRouter. For example in userRouter i have
const router = express.Router();
router.get('/', UserController.getUsers);
router.get('/:idoremail', UserController.getUserByIdOrEmail);
router.post('/', UserController.createNewUser)

export const { handler }


I tried the schedule with netlify.toml that worked: 
![image|690x147](upload://cAaGkRwnBAwnz4mPfr9Ygt1IiNk.png)

Thank you - this works. 

Would be great if you can help with tips using debugging locally.

Okay, so do you still need help, or is this resolved?