thgh / vercel-sapper

Vercel builder for Sapper with SSR enabled
MIT License
191 stars 25 forks source link

Does this work with Vercel serverless functions? #30

Closed joeybellerose closed 4 years ago

joeybellerose commented 4 years ago

I'm able to get server routes to work locally but get a 500 error when I deploy to Vercel. My folder structure looks like this: folderstructure

Here's my now.json file: now

Here's my server.js file: server

benmccann commented 4 years ago

@joeybellerose can you provide any more details about what the error is?

benmccann commented 4 years ago

Also, I see you have a now.json. Are you running the vercel command? I wonder if maybe it'd need to be updated to vercel.json?

joeybellerose commented 4 years ago

@benmccann The error i get is 500 "Unexpected token O in JSON at position 0"

I have been running the vercel command and tried changing to vercel.json to no avail.

Also...it looks like vercel recognizes a function named index but i have no idea where that is coming from.

thgh commented 4 years ago

That index is the function that runs serverless https://github.com/thgh/now-sapper/blob/master/index.js#L73)

The screenshots look ok, what happens when you visit /company/ticker.json ? It looks like that response might contain an error that will help you further.

joeybellerose commented 4 years ago

@thgh Thanks for the clarification. I get the following response when I visit /company/ticker.json:

Only absolute URLs are supported

Also in [ticker].svlete my fetch looks like this const res = await this.fetch(company/${ticker}.json);

Does this help?

thgh commented 4 years ago

You probably want this instead: (note the URL starting with /)

this.fetch(`/company/${ticker}.json`);
joeybellerose commented 4 years ago

@thgh Thanks so much! That did the trick.....I also overlooked that you need to have environment variables for Production as well as Preview. Thanks again for all the help!