Hi,
I’m struggling with getting started on fastify framework. Thanks for the help ! Really appreciated guys if you can help me on this issue
Code on main Fastify file
const { createAgent } = require("@forestadmin/agent");
const {
createSequelizeDataSource,
} = require("@forestadmin/datasource-sequelize");
module.exports = async function (fastify, opts) {
await fastify.register(import("@fastify/middie"));
await db.connect();
await createAgent({
authSecret: process.env.FOREST_AUTH_SECRET,
envSecret: process.env.FOREST_ENV_SECRET,
isProduction: process.env.NODE_ENV === "production",
})
// Create your Sequelize datasource
.addDataSource(createSequelizeDataSource(db.sequelize))
// Replace "myFastifyApp" by your Fastify application
.mountOnFastify(fastify)
.start();
// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
fastify.register(bearerAuthPlugin, { keys });
//
fastify.register(AutoLoad, {
dir: path.join(__dirname, "plugins"),
options: Object.assign({}, opts),
});
// This loads all plugins defined in routes
// define your routes in one of these
fastify.register(AutoLoad, {
dir: path.join(__dirname, "routes"),
options: Object.assign({}, opts),
});
};
Observed behavior
/forest endpoint is not mounted on fastify web server. It keep getting me 404 not found errors on /forest endpoints
Failure Logs
{"level":30,"time":1702983449798,"pid":7344,"hostname":"WIN11","reqId":"req-b","msg":"Route OPTIONS:/forest not found"}
{"level":30,"time":1702983449798,"pid":7344,"hostname":"WIN11","reqId":"req-b","res":{"statusCode":404},"responseTime":0.2769999988377094,"msg":"request completed"}
{"level":30,"time":1702983449799,"pid":7344,"hostname":"WIN11","reqId":"req-c","req":{"method":"GET","url":"/forest","hostname":"localhost:3000","remoteAddress":"::1","remotePort":54327},"msg":"incoming request"}
{"level":30,"time":1702983449799,"pid":7344,"hostname":"WIN11","reqId":"req-c","msg":"Route GET:/forest not found"}
{"level":30,"time":1702983449799,"pid":7344,"hostname":"WIN11","reqId":"req-c","res":{"statusCode":404},"responseTime":0.1569999996572733,"msg":"request completed"}
Package.json
{
"name": "forest-admin-poc",
"version": "1.0.0",
"description": "This project was bootstrapped with Fastify-CLI.",
"main": "app.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "tap \"test/**/*.test.js\"",
"start": "fastify start -l info app.js",
"dev": "fastify start -w -l info -P app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@fastify/auth": "^4.4.0",
"@fastify/autoload": "^5.0.0",
"@fastify/bearer-auth": "^9.1.0",
"@fastify/middie": "^8.3.0",
"@fastify/sensible": "^5.0.0",
"@forestadmin/agent": "^1.36.10",
"@forestadmin/datasource-sequelize": "^1.5.26",
"dotenv": "^16.3.1",
"fastify": "^4.0.0",
"fastify-cli": "^5.9.0",
"fastify-plugin": "^4.0.0",
"mariadb": "^3.2.2",
"sequelize": "^6.35.2"
},
"devDependencies": {
"tap": "^16.1.0"
}
}