ChrisThornham
ChrisThornham
SSolidJS
Created by ChrisThornham on 12/5/2024 in #support
Help: Preflight OPTIONS Requests In SolidStart. I'm Lost!
I'm on it.
18 replies
SSolidJS
Created by ChrisThornham on 12/5/2024 in #support
Help: Preflight OPTIONS Requests In SolidStart. I'm Lost!
Ok. Thanks. Should I submit an official request somewhere to add an OPTIONS handler? I don't mind helping with that.
18 replies
SSolidJS
Created by ChrisThornham on 12/5/2024 in #support
Help: Preflight OPTIONS Requests In SolidStart. I'm Lost!
Yes, I agree that adding an OPTIONS handler is the best solution. Just to clarify, you're saying that I should check the route inside the middleware before executing the if statement on the request?
18 replies
SSolidJS
Created by ChrisThornham on 12/5/2024 in #support
Help: Preflight OPTIONS Requests In SolidStart. I'm Lost!
@Brendonovich you're a legend! It works! I can't thank you enough. Some version of your example would be a wonderful addition to the API Routes page in the SolidStart docs.
18 replies
SSolidJS
Created by ChrisThornham on 12/5/2024 in #support
Help: Preflight OPTIONS Requests In SolidStart. I'm Lost!
Thank you @Brendonovich ! Let me work on this.
18 replies
SSolidJS
Created by ChrisThornham on 12/5/2024 in #support
Help: Preflight OPTIONS Requests In SolidStart. I'm Lost!
Thanks @Madaxen86 I found those as well and set up the netlify.toml file as suggested. Unfortunately, I’m still getting blocked by the preflight OPTIONS request.
18 replies
SSolidJS
Created by ChrisThornham on 12/5/2024 in #support
Help: Preflight OPTIONS Requests In SolidStart. I'm Lost!
That would definitely be REALLY helpful. I can’t get any of my POST requests working. I find the middleware docs to be pretty sparse. Can you point to any examples or references that I could use to set up OPTIONS requests in middleware?
18 replies
SSolidJS
Created by ChrisThornham on 12/5/2024 in #support
Help: Preflight OPTIONS Requests In SolidStart. I'm Lost!
Ok.. I've kept digging. I'm using Netlify to host the backend and using a mobile client to call the API. This works:
import { APIEvent } from "@solidjs/start/server";

export async function GET({ request }: APIEvent) {
// Fetch todos from external API
const response = await fetch("https://jsonplaceholder.typicode.com/todos");
const todos = await response.json();

// Create a new response with CORS headers
return new Response(JSON.stringify(todos), {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*', // Allows all origins (use carefully in production)
'Access-Control-Allow-Methods': 'GET,HEAD,POST,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
},
});
}
import { APIEvent } from "@solidjs/start/server";

export async function GET({ request }: APIEvent) {
// Fetch todos from external API
const response = await fetch("https://jsonplaceholder.typicode.com/todos");
const todos = await response.json();

// Create a new response with CORS headers
return new Response(JSON.stringify(todos), {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*', // Allows all origins (use carefully in production)
'Access-Control-Allow-Methods': 'GET,HEAD,POST,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
},
});
}
The POST request returns a "Success!" message. But when I send and OPTIONS request to this endpoint, I get a HTML page returned and a 200 status. I should be getting a 204.
import { APIEvent } from "@solidjs/start/server";

export async function OPTIONS({ request }: APIEvent) {
return new Response(null, {
status: 204, // No content
headers: {
"Access-Control-Allow-Origin": "*", // Allow all origins (adjust for production)
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
},
});
}

export async function POST({ request }: APIEvent) {
const body = await request.json();
// Handle your POST logic here
return new Response(JSON.stringify({ message: "Success!" }), {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
});
}
import { APIEvent } from "@solidjs/start/server";

export async function OPTIONS({ request }: APIEvent) {
return new Response(null, {
status: 204, // No content
headers: {
"Access-Control-Allow-Origin": "*", // Allow all origins (adjust for production)
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
},
});
}

export async function POST({ request }: APIEvent) {
const body = await request.json();
// Handle your POST logic here
return new Response(JSON.stringify({ message: "Success!" }), {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
});
}
So it appears I don't know how to handle OPTIONS requests in SolidStart. What am I missing? How do I handle preflight OPTIONS requests in SolidStart?
18 replies
SSolidJS
Created by ChrisThornham on 11/29/2024 in #support
Vercel & CORS Problem
The app on vercel is acting as a backend for mobile devices. I added the app to Netlify and everything worked perfectly. It must be something to do with Vercel’s servers.
3 replies
SSolidJS
Created by ChrisThornham on 11/27/2024 in #support
API Endpoint Security Question
Thank you!
3 replies
SSolidJS
Created by ChrisThornham on 11/26/2024 in #support
Help Configuring SolidStart with Capacitor JS
Thank you. I'm currently going down the rabbit hole. Haha.
6 replies
SSolidJS
Created by ChrisThornham on 11/26/2024 in #support
Help Configuring SolidStart with Capacitor JS
@Atila Thanks! I'll look at Tauri today. I'm just getting started with converting this app to mobile, so maybe Tauri is a better fit.
6 replies
SSolidJS
Created by ChrisThornham on 11/26/2024 in #support
Help Configuring SolidStart with Capacitor JS
I think I figured this out. It appears that you can't use "use server" with Capacitor. This means any server actions will need to be rewritten into API endpoints. So, if you're like me and built your app with SSR and heavy use of "use server", you'll have a lot of code to rewrite. 🤦‍♂️
6 replies
SSolidJS
Created by ChrisThornham on 10/3/2024 in #support
SRR And Web Crawlers. Help Me Understand
Sweet! Thank you. I agree. The "get indexed" timeline is extremely variable. I've been an online entrepreneur for 15+ years now, and I still don't fully understand how Google's algorithm works. Haha. Have a good one.
5 replies
SSolidJS
Created by ChrisThornham on 10/3/2024 in #support
SRR And Web Crawlers. Help Me Understand
Haha. Chicken or egg. It's hard to build a sitemap without a crawler. I just coded a custom sitemap generator using import.meta.glob from vite. Do you think it will work if I add that sitemap to my site and a robots.txt file?
5 replies
SSolidJS
Created by gsoutz on 10/3/2024 in #support
How do I do something after a redirect, like reload the page, or in this case reconnect a websocket?
I think you'll have to recall your getUser function on each load. Or store the current user name. Then check it on page load. If the user name is the same, proceed. But if the user name has changed, rerun getUser.
10 replies
SSolidJS
Created by gsoutz on 10/3/2024 in #support
How do I do something after a redirect, like reload the page, or in this case reconnect a websocket?
Couldn't you use onMount() or createEffect() on the page you are redirecting to? Basically, when this page loads, check for a websocket connection. If it exists, return. If not, reconnect.
10 replies
SSolidJS
Created by ChrisThornham on 9/13/2024 in #support
Can I Pass `createAsync()` a Signal?
Just read about it. I get it now. That's a cool addition to the tool belt. Thanks again!
15 replies
SSolidJS
Created by ChrisThornham on 9/13/2024 in #support
Can I Pass `createAsync()` a Signal?
Oh cool. I'll dig through that. Thanks!
15 replies
SSolidJS
Created by ChrisThornham on 9/13/2024 in #support
Can I Pass `createAsync()` a Signal?
Haha. For people like myself who are still learning, definitely!
15 replies