question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Confusing example, auto prefixing

See original GitHub issue

💬 Questions and Help

In the README there is the following example:

// index.js
fastify.register(AutoLoad, {
  dir: path.join(__dirname, 'services'),
  options: {}
})

// /services/items/get.js
module.exports = function (f, opts, next) {
  f.get('/:id', (request, reply) => {
    reply.send({ answer: 42 })
  })

  next()
}

// /services/items/list.js
module.exports = function (f, opts, next) {
  f.get('/', (request, reply) => {
    reply.send([0, 1, 2])
  })

  next()
}

My test: index.ts

server.register(AutoLoad, {
	dir: path.join(__dirname, 'modules/routes/v1'),
	options: { prefix: '/v1' },
	includeTypeScript: true
})

modules/routes/v1/domains/index.ts

module.exports = (server, opts, next) => {
	server.route({
		url: "/:url",
		logLevel: "warn",
		method: ["GET"],
		schema: {
			params: {
				id: { type: 'string', maxLength: 2 },
			},
			response: {}
		},
		handler: async (request, reply) => {
			return reply.send({ url: request.params.id, works: true });
		}
	});
	next();
};

Generated route: GET /v1/:url

Looking at the README, I was under the impression that this would load routes using the directories path. Am I doing something wrong or I interpreted that the wrong way?

I removed the fastify-plugin route and converted it to a more standard one, but it didn’t change anything it seems.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mcollinacommented, Jan 1, 2020

The issue is caused by directories without any js files, would you like to send a PR to fix this?

See https://github.com/fastify/fastify-autoload/blob/2deb5f00eb4ab6e8a6a16cac23983ca0f8f21443/index.js#L78.

0reactions
mcollinacommented, Jul 15, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is Vendor Prefixing Dead? - CSS-Tricks
Let's take a quick stroll down memory-lane to revisit how vendor prefixing CSS properties came to be. I hope I don't trigger PTSD...
Read more >
WORD PARTS: MOST COMMONLY USED PREFIXES
WORD PARTS: MOST COMMONLY USED PREFIXES. PREFIX. MEANING. EXAMPLE a (or ab) without or not amoral, abnormal ab away, from abhor, absent.
Read more >
Do We STILL Need to Use Vendor Prefixes in CSS? - YouTube
Remember when you needed a -webkit prefix on EVERY CSS property? Do we still need to use CSS prefixes anymore? Is your website...
Read more >
Prepended auto-prefixed css variables in Visual Studio Code
When I type in a prefix-able property, such as border-radius the auto-prefixer adds -webkit-border-radius (as expected). But it appends it to ...
Read more >
Spelling Rules for Prefixes: Overview & Exceptions - Study.com
Re + do = redo. Here's one more example. ''Hydro'' means ''water'', so if you want to talk about something that's powered by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found