thisguy
thisguy

Reputation: 63

How to rewrite route with NPM serve

Hello I'm using the serve npm package. I am trying to serve static files on a different route. Let's say I have the following directory structure that I'm trying to serve:

I'm trying to serve it on a specific route using the serve package, but I can't seem to get the rewrite syntax correct. I'm trying to serve it on the custom route. What I have as the config is:

{
  "rewrites": [
    {"source":"custom/**", "destination":""}
  ]
}

Any help would be much appreciated.

Upvotes: 2

Views: 2483

Answers (3)

mtkopone
mtkopone

Reputation: 6443

If - like me - you came here looking for a way to use serve to rewrite paths, then this should do the trick:

{
  "rewrites": [
    { "source": "custom/:path", "destination": ":path" }
  ]
}

Upvotes: 0

James Perih
James Perih

Reputation: 1384

I'm confident that empty string will throw serve for a loop.

Try:

{
  "rewrites": [
    {"source":"custom/**", "destination":"/**"}
  ]
}

That assumes your folder structure is in the same folder you told serve to operate on. You would change the destination if your files were in a different folder.

Eg:

$ pwd
/var/web/site

$ ls
old_files/ index.html

$ ls old_files
index.html index.js helpers/

Your config should be:

{
  "rewrites": [
    {"source":"custom/**", "destination":"/old_files/**"}
  ]
}

Upvotes: 0

Israel Omar
Israel Omar

Reputation: 54

Maybe you need export your server and call baseURL

in helper

export const server = {
 baseURL: 'http:localhost:3000'
}

i expect that resolve your problem

Upvotes: 0

Related Questions