Sheik
Sheik4mo ago

Github Actions file_server with headers

Hello, I have my portfolio deployed in deno deploy (developed in Angular and I use Github Actions for the bundle and deploy), and I was interested in adding the header to my deploy.yml of my github actions Cache-Control: max-age=336000 locally I can use deno run -A https://deno.land/std@0.217.0/http/file_server.ts -H "Cache-Control: max-age=336000" but in a github action I can't use - name: Upload to Deno Deploy uses: denoland/deployctl@v1 with: project: "ricardorobles" entrypoint: "https://deno.land/std@0.217.0/http/file_server.ts -H 'Cache-Control: max-age=2592000'" Does anyone know how I can add that header?
2 Replies
Deno AI Helper
Deno AI Helper4mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided in your message, it seems like you're trying to pass command-line arguments to the file_server.ts script within the GitHub Actions workflow, which might not be the correct approach when using the deployctl action. The deployctl GitHub Action is designed to deploy your code to Deno Deploy, and it doesn't accept command-line arguments for the file_server.ts script in the entrypoint field. The entrypoint field should only contain the path to your entry file. Here's a suggestion that is not based on the Deno documentation, so please double-check the accuracy of this advice: To set custom headers like Cache-Control, you would typically need to modify the server code to include these headers in the response. Since you're using file_server.ts directly, you might need to create a custom version of file_server.ts that sets the desired headers. You could create a custom server file in your repository that imports file_server.ts and adds the Cache-Control header to the responses. Then, you would use this custom server file as the entrypoint in your GitHub Actions workflow. Here's a rough example of what that custom server file might look like:
// custom_file_server.ts
import { serveFile, serveDir, ServerRequest } from "https://deno.land/std@0.217.0/http/file_server.ts";

async function handler(req: ServerRequest) {
const response = await serveFile(req, "path_to_your_files");
response.headers.set("Cache-Control", "max-age=336000");
req.respond(response);
}

await serveDir({ handler });
// custom_file_server.ts
import { serveFile, serveDir, ServerRequest } from "https://deno.land/std@0.217.0/http/file_server.ts";

async function handler(req: ServerRequest) {
const response = await serveFile(req, "path_to_your_files");
response.headers.set("Cache-Control", "max-age=336000");
req.respond(response);
}

await serveDir({ handler });
Then, in your GitHub Actions workflow, you would update the entrypoint to point to your custom server
Deno AI Helper
Deno AI Helper4mo ago
file:
- name: Upload to Deno Deploy
uses: denoland/deployctl@v1
with:
project: "ricardorobles"
entrypoint: "path_to_your_custom_file_server.ts"
- name: Upload to Deno Deploy
uses: denoland/deployctl@v1
with:
project: "ricardorobles"
entrypoint: "path_to_your_custom_file_server.ts"
Remember to replace "path_to_your_files" with the actual path to your Angular build output and "path_to_your_custom_file_server.ts" with the actual path to your custom server file. Please note that this is a general suggestion and may require adjustments to fit your specific use case. It's important to test this locally before deploying to ensure it works as expected.