John Keyes
John Keyes

Reputation: 5604

Specifying content-type for static resources in Nuxt

Using the built-in Nuxt server, I would like to serve the static file /.well-known/apple-app-site-association with content-type application/json. However, as the file doesn't have a .json file extension the content-type is returned as application/octet-stream. Is it possible to set some specific config for this file/route to return the content-type?

Upvotes: 2

Views: 1708

Answers (1)

John Keyes
John Keyes

Reputation: 5604

After examining the source of serve-static and then looking at the source of the nuxt.js static file integration I eventually figured it out.

I added the following property to nuxt.config.js:

    render: {
        static: {
            setHeaders: (resp, path) => {
                if (
                    resp.req.originalUrl ===
                    '/.well-known/apple-app-site-association'
                ) {
                    resp.setHeader('Content-Type', 'application/json')
                }
            },
        },
    }

This property is referenced in the nuxt.js docs but not from the static directory docs.

Upvotes: 4

Related Questions