Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load local .js and .css files when using the server (enhancement/puppeteer) #366

Open
m-rm opened this issue Aug 31, 2022 · 2 comments
Open
Assignees

Comments

@m-rm
Copy link

m-rm commented Aug 31, 2022

We would like to load additional local resources when using the server, but it seems that only the "server" section of the configuration is used while starting the server. During the actual HTTP requests, nothing in "customCode" is applied. Is this the case due to security reasons or is this feature not complete yet?

@iherbak
Copy link

iherbak commented Nov 17, 2023

Same issue here. By security reasons allowFileResources is always false on http request, but how could we include js files then?

Thanks

@m-rm
Copy link
Author

m-rm commented Nov 17, 2023

I found a workaround that works for my use case: In addition to highcharts-export-server I start an express server that is able to serve my JS files and only binds to localhost. I then use the scripts section of the node-export-server config to load the scripts.

Here's my express server code:

const express = require('express')
const cors = require('cors');
require('dotenv').config()

const app = express()
const port = process.env.HC_STATIC_PORT || 3000

app.use(cors({
    origin: '*' // We need CORS headers because otherwise the Pupeteer browser instance will block the files. Using localhost as origin doesn't work. Since we only bind to localhost * should be ok
}));

app.use(express.static('static'))

app.listen(port, 'localhost', () => {
  console.log(`Highcharts Node.js export server static file app listening on port ${port}`)
})

One important side note: the scripts are combined and cached. If you change them the cached version is not updated. You need to delete node_modules/highcharts-export-server/.cache to update the scripts. Also don't forget to add moment and lodash to the scripts section, because it's there by default, but if you define it it's overwritten.

If you need to load CSS files it's possible to also host them locally using the express server and then load them through JavaScript using the customCode request parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants