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.

How to overwrite or remap one directory to another

See original GitHub issue

Is it possible to “remap” a directory to another using polka and sirv?

I created a repository to test the following code:

// index.js
const polka = require('polka');
const sirv  = require('sirv');

const { PORT=3000 } = process.env;

polka()
  // Make "localhost:3000/components" to serve content from "public/compiled_components"
  .use('components', sirv('public/compiled_components'))

  // And everything else remains the same, on "public"
  .use(sirv('public'))

  .listen(PORT, err => {
    if (err) throw err;
    console.log(`Running on localhost:${PORT}`);
  });

My project has the following structure:

project
│   index.js
│
└───public
│   │
│   └───components (non compiled components)
│       │   component1.txt
│       │   component2.txt
│       │   ...
│   └───compiled_components (automatic compiled components, during development time)
│       │   component1.txt
│       │   component2.txt
│       │   ...

But, on the path localhost:3000/components, instead of serving the content of public/compiled_components it is still serving the content of public/components

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
lukeedcommented, Jun 13, 2019

Great! The last sample will only work in the next version of Polka. The reason it isn’t currently working is because stable polka is running use() before use(‘/foo’)

0reactions
paulocoghicommented, Jun 13, 2019

Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to move and overwrite subdirectories (and files) to parent ...
How i usually do this: packing the subdir content into a tarball, moving the tarball up to the parent directory and then extract...
Read more >
How do I copy files, overwriting existing files? - Stack Overflow
I have the following code to copy the files from one directory to another directory... const string sourceDir = @"C:\AppProject\Smart\SmartStaff\site\document"; ...
Read more >
Make scp always overwrite or create directory - Server Fault
I am using scp to copy a directory from one remote server to a new directory (IE just changing the name) on another...
Read more >
How can I copy a (big) directory over another changing only ...
You can use rsync to do this, the command I use is rsync -tr "folder to copy from" "folder to copy to". e.g....
Read more >
The DistCp - Update and Overwrite - Cloudera Documentation
The DistCp -update option is used to copy files from a source that does not exist at the target, or that has different...
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