functions icon indicating copy to clipboard operation
functions copied to clipboard

Static does not work with fingerprinting

Open mokkabonna opened this issue 3 years ago • 2 comments

Steps to reproduce Steps to reproduce the behavior:

  1. Setup static with fingerprinting
@static
fingerprint true
  1. Use static helper to get fingerprinted path of asset
  2. deploy

Expected behavior Expect the static helper to get the fingerprinted path. It does not. it only get the non fingerprinted path.

Seems this is the problem: Why does the code look here(node_modules folder) https://github.com/architect/functions/blob/main/src/static/index.js#L18 for the manifest? While the file is written to /public/static.json? https://github.com/architect/deploy/blob/main/src/static/publish/write-static-manifest.js#L11

@architect/functions 5.2.3 @architect/architect 10.7.1

mokkabonna avatar Nov 23 '22 07:11 mokkabonna

I ended up working around this with a custom plugin which copies the file where it needs to be during hydrate.

module.exports = {
  hydrate: {
    copy: async ({ arc, inventory, copy }) => {
      await copy({
        source: "./public/static.json",
        target:
          "@architect/shared/static.json",
      });
    },
  },
};

beckelmw avatar Jun 01 '23 22:06 beckelmw

I was also encountering this issue together with the typescript plugin. I suspect the problem is that with typescript esbuild bundles the whole function but the static sill tries to look up the static.json on the file system

Xiphe avatar Jun 19 '23 21:06 Xiphe

I cannot reproduce this issue with a basic arc app like this:

@app
stattest

@http
get /

@static
fingerprint true

I then added a dummy foo.css to the public/ directory. Finally, I set up the get-index route code to look like this:

import arc from '@architect/functions'

export async function handler (req) {
  return {
    statusCode: 200,
    headers: {
      'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0',
      'content-type': 'text/html; charset=utf8'
    },
    body: `
<html>
${arc.static('foo.css')}
</html>
`

When running locally in sandbox, the asset path is not fingerprinted (which is fine for local emulation). After npx arc deploying the app, though, the displayed value is fingerprinted.

filmaj avatar Mar 22 '25 13:03 filmaj

Given this is not an issue with @architect/functions per se - which works as advertised in standard JS projects - and rather this is, at least as far as I can tell from the comments, an issue with the interaction between the plugin-typescript project and architect/functions, I have transfered and reopened the following issue on the typescript plugin: https://github.com/architect/plugin-typescript/issues/19. I believe that issue is the correct place for further discussion about this problem, so please continue any relevant conversation there. Thanks!

Closing this issue.

filmaj avatar Mar 22 '25 13:03 filmaj