-
Notifications
You must be signed in to change notification settings - Fork 11
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
Server.ts changes are not being process after deploying to nelify but works fine locally #135
Comments
Hi @mrrohit1! For your usecase, I'd recommend you to use an Edge Function. Here's a draft for how it could look: // .netlify/edge-functions/redirect-and-sanitize
import {
HTMLRewriter
} from 'https://ghuc.cc/worker-tools/html-rewriter/index.ts'
export default (request, context) => {
const redirectUrl = redirectMap[request.url];
if (redirectUrl) {
return Response.redirect(redirectUrl, 301);
}
const response = await context.next()
if (!response.headers.get("content-type").startsWith("text/html")) {
return response
}
return new HTMLRewriter()
.on("#ng-state", {
element(element) {
const state = JSON.parse(element.innerHTML);
const sanitizedState = sanitizeState(state);
element.innerHTML = JSON.stringify(sanitizedState);
},
})
.transform(response)
}
export const config = {
path: "/*"
} You'll notice that I replaced your Regex-based approach with Let us know if that helps! Sorry for the confusion with |
Hi, @Skn0tt. Here is my post on the support forum regarding that issue: https://answers.netlify.com/t/netlify-redirects-to-api-server-not-working-on-angular-ssr-website/119988/5. In my case, I wanted to use a custom edge function as a proxy. Is there any way to make custom edge functions work with SSR, for example, by excluding certain paths? |
cc @serhalp |
@yehor-akunishnikov As my colleague mentioned in reply to your post, I don't believe that's possible currently. However, you should be able to use a custom Netlify Function that runs at the origin, instead of a Netlify Edge Function that runs at the edge. Is that an acceptable workaround for your use case? |
@serhalp I'll give it a try, thanks. |
@serhalp thanks for the above! could you please point me how to set up a Netlify Function to run at the origin? I was not able to find that trigger. would be great if the fn call could be tied to a path prefix as well 🙏 |
@daroczig I could've been clearer! What I meant was that Netlify Functions run at the origin and Netlify Edge Functions run at the edge. So the suggestion here was to use Netlify Functions: https://docs.netlify.com/functions/overview/. That page should have everything you need! |
@daroczig, |
@serhalp I went through those pages and tried deploying a Netlify Function with a custom FTR this is what I tried as a POC: import type { Config, Context } from "@netlify/functions";
export default async (request: Request, context: Context) => {
console.log(url);
return new URL("https://reqres.in/api/users?page=2", request.url);
};
export const config: Config = {
path: "/foobar/*",
}; |
Describe the bug
Update my server.ts file to manage 301 redirect and added sanitization for json in final souuce code but both changes are not working, i can see its working locally but after deploying to netlify its not working
To Reproduce
Steps to reproduce the behavior:
redirectMap:
sanitize-state :
Expected behavior
after deployment redirect should work but its not working and same for sanitize state
Versions
If you're using the CLI to build
N/A
If you're using file-based installation
reason for using redirect in server.ts because redirect is not supported in SSR and i have to redirect more than 3000 urls
The text was updated successfully, but these errors were encountered: