Home > Blockchain >  express js: is there a way to map all the rest of url as one parameter?
express js: is there a way to map all the rest of url as one parameter?

Time:11-26

The code segment is:

  app.get('/api/photo/:S3ObjectKey', photo.get);

And photo.get():

  const S3ObjectKey = req.params.S3ObjectKey;
  if (!S3ObjectKey) {
    console.log("No S3ObjectKey specified");
  }
  console.log("S3ObjectKey: ", S3ObjectKey);

  const canShow = true;
  if (canShow) {
    const bucket_name = process.env.AWS_S3_BUCKET_NAME;
    const data = await S3.getFile(bucket_name, S3ObjectKey);
    data.Body.pipe(res);
  }

Is there a way to map all the rest of url as one parameter, such that:

a GET request to https://mylovelydomain/api/photo/bucketMyPhoto/2020/07/12/home/table.jpeg would hit the api endpoint and S3ObjectKey has the value bucketMyPhoto/2020/07/12/home/table.jpeg?

CodePudding user response:

Express uses enter image description here

  • Related