Cannot deploy new API routes using Vercel (Zeit Now) - node.js

I've been developing an Node.js/Express.js API and running it on localhost. I set up the API to be hosted on Zeit Now (currently Vercel).
When I first started the API, I deployed 2 routes to Zeit Now using the "Now" command. Those routes worked fine when I accessed them. Now about half a year later, I tried to deploy a bunch of additional routes view the "Now" command, but when I go to access the new routes on the deployed version, they return a 404 status.
The new routes are in now.json.
This is the format of this file:
{
"version": 2,
"builds": [{ "src": "index.js", "use": "#now/node-server" }],
"routes": [
{
"src": "/login",
"dest": "/index.js",
"methods": ["POST"]
},
{
"src": "/exampleget",
"dest": "/index.js",
"methods": ["GET"]
},
{
"src": "/examplepost",
"dest": "/index.js",
"methods": ["POST"]
}
]
}
The route that is not working is /login. I've also tried with other routes not shown in this file. They didn't work either.
Can I no longer deploy routes this way after the transition from Zeit to Vercel?

Related

Error while deploying Node js application to Vercel

Trying to deploy Node server to Vercel but getting the following error:
The structure:
Besides the versel.json file is present:
{
"version": 2,
"builds": [
{
"src": "./server.js",
"use": "#vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/"
}
]
}
So what could be the reason for the error?

How to serve NodeJS form app using zeit now server

I am running a simple nodejs form processing app on zeit now server and deploying using now CLI scripts.
This Node app although working well on the localhost within the said port number (like this: http://localhost:8081/myaction), however the same function is not workinig for me on the zeit server wherein I replace the localhost with the server URL given by NOW build script.
Here is my now.json and I am also providing access to the git repository which has the node server app thaat processes the form, sends an E-mail and serves a Thank You page in the last step.
Node Server App repo: https://github.com/jnsrikanth/node-form-server2
now.json file contents:
{
"version": 2,
"builds": [{ "src": "index.js", "use": "#now/node-server" }],
"routes": [
{
"src": "/public/thank-you/dist/",
"dest": "/index.html",
"methods": ["GET"]
},
{
"src": "/",
"dest": "/index.js",
"methods": ["POST"]
}
]
}
The package.json and the remaining code can be found in the repository. It would be great if I can find some pointers here.
Also please note that in my form I am calling action="https://zeit-url:8081/myaction" method="POST" where 8081 is the port on which the express app is listening for processing the POST method with form data.
In your now.json replace / with /myaction
...
{
"src": "/myaction",
"dest": "/index.js",
"methods": ["POST"]
}
...
And just call https://zeit-url/myaction (without port number)
I hope it will help you
I would suggest you to convert that now.json into a vercel.json and, based on the github repo you provided, update it so looks like:
"version": 2,
"builds": [
{
"src": "index.js",
"use": "#vercel/node"
}
],
"routes": [
{
"src": "/public/thank-you/dist/",
"dest": "/public/index.html",
"methods": ["GET"]
},
{
"src": "/",
"dest": "/index.js",
"methods": ["POST"]
}
]
You need to verify this server runs without problems on local machine.
Since you are using the builds vercel.json option, you need to ensure all the dependencies, as node_modules etc are uploaded to vercel, either by deploying file from the vercel-cli, or using some pipeline or CI action.

Problem to deploy a node / express API using now.sh

I'm trying to deploy a node / express API that has several endpoints for use at now.sh.
My question is how to correctly configure the file now.json.
leave the image where you can see the complete structure of the project, the main path would be the ./src/ where are all the folders and files.
The main entrypoint is http://localhost:3000/api/v1/ for localhost
I delete the file now.json and from the terminal I paste the now command, and then I generated the deployment in the following path
https://ryuanime.chrismichael.now.sh
But when I try to go to https://ryuanime.chrismichael.now.sh/api/v1 it shows me 404: NOT_FOUND
Image
source code
now.json
{
"version": 2,
"name": "ryuanime",
"builds": [
{
"src": "src/index.ts",
"use": "#now/node-server"
}
],
"routes": [{"src": "/(.*)", "dest": "/src/index.ts"}]
}
For some reason it worked by referring to
"src": "./src/index.ts"
and not
"src": "src / index.ts",
{
"name": "ryuanime-api",
"version": 2,
"builds": [
{
"src": "./src/index.ts",
"use": "#now/node-server"
}
],
"routes": [
{ "src": "/(.*)", "dest": "/src/index.ts" }
]
}

How to setup now index.html?

I am trying to deply my node.js app to NOW,
But when i deploy all i see is the root folder with all the files...
I am supposed to have an index.html file, but i dont know where this happens or where i should set this up?
In webpack? in start.js?
Any ideas?
In my project, i have start.js and app.js
So I guess, I should use start.js on the now.json config file
{
"version": 2,
"builds": [
{ "src": "start.js", "use": "#now/node" },
{ "src": "index.html", "use": "#now/static" }
]
}
But I get an error and logs like:
'The lambda function size (8.98mb) exceeds the configured limit (5mb). You may increase this by supplying maxLambdaSize to the build config'`
As stated in the error, You have to add maxLambdaSize to your build config.
{
"name": "Your Project Name",
"alias": ["yourAliasGoesHere"],
"version": 2,
"builds": [
{
"src": "index.js", //put your own stuff here
"use": "#now/node-server",
"config": { "maxLambdaSize": "10mb" } //right here
}
]
}
Increase or decrease the maxLambdaSize as needed.

Configure Ingress controller to forward custom http headers

We are setting up an AKS cluster on Azure, following this guide
We are running 5 .Net Core API's behind an ingress controller, everything works fine, requests are being routed nicely.
However, in our SPA Frontend, we are sending a custom http header to our API's, this header never seems to make it to the API's, when we inspect the logging in AKS we see the desired http header is empty.
In development, everything works fine, we also see the http header is filled in our test environment in AKS, so i'm guessing ingress is blocking these custom headers.
Is there any configuration required to make ingress pass through custom http headers?
EDIT:
{
"kind": "Ingress",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "myappp-ingress",
"namespace": "myapp",
"selfLink": "/apis/extensions/v1beta1/namespaces/myapp/ingresses/myapp-ingress",
"uid": "...",
"resourceVersion": "6395683",
"generation": 4,
"creationTimestamp": "2018-11-23T13:07:47Z",
"annotations": {
"kubernetes.io/ingress.class": "nginx",
"nginx.ingress.kubernetes.io/allow-headers": "My_Custom_Header", //this doesn't work
"nginx.ingress.kubernetes.io/proxy-body-size": "8m",
"nginx.ingress.kubernetes.io/rewrite-target": "/"
}
},
"spec": {
"tls": [
{
"hosts": [
"myapp.com"
],
"secretName": "..."
}
],
"rules": [
{
"host": "myapp.com",
"http": {
"paths": [
{
"path": "/api/tenantconfig",
"backend": {
"serviceName": "tenantconfig-api",
"servicePort": 80
}
},
{
"path": "/api/identity",
"backend": {
"serviceName": "identity-api",
"servicePort": 80
}
},
{
"path": "/api/media",
"backend": {
"serviceName": "media-api",
"servicePort": 80
}
},
{
"path": "/api/myapp",
"backend": {
"serviceName": "myapp-api",
"servicePort": 80
}
},
{
"path": "/app",
"backend": {
"serviceName": "client",
"servicePort": 80
}
}
]
}
}
]
},
"status": {
"loadBalancer": {
"ingress": [
{}
]
}
}
}
I ended up using the following configuration snippet:
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header My-Custom-Header $http_my_custom_header;
nginx makes all custom http headers available as embedded variable via the $http_ prefix, see this
If I want my ingress controller pass a custom header to my backend service, I can use this annotation in my ingress rule
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_headers "Request-Id: $req_id";
By default ingress doesn’t pass through headers with underscores.
You could set
enable-underscores-in-headers: true
See https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#enable-underscores-in-headers
Also Ingress doesn’t pass through Authorization header

Resources