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" }
]
}
Related
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?
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?
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.
I have an electron app and I got this error when run electron-builder build.
Error: Application entry file "main.js" in the "/project/dist/release/mac/demo.app/Contents/Resources/app.asar" does not exist. Seems like a wrong configuration.
This is package.json. I have set the main to dist/electron.js but I don't understand why it keep saying main.js doesn't exist.
...
"main": "dist/electron.js",
"build": {
"productName": "demo",
"appId": "com.auspost.pos",
"files": [
"dist/",
"node_modules/**/*",
"package.json",
"dist/electron.js"
],
"directories": {
"output": "dist/release"
},
"dmg": {
"contents": [
{
"x": 130,
"y": 220
},
{
"x": 410,
"y": 220,
"type": "link",
"path": "/Applications"
}
]
},
"win": {
"target": [
"nsis",
"msi"
],
"icon": "./electron/assets/icons/win/app.ico"
},
"publish": {
"provider": "github"
}
},
...
"devDepencencies": {
"electron": "^5.0.2",
"electron-builder": "^20.41.0",
"electron-webpack": "^2.6.2",
}
Finally figure out that because the project has electron-webpack dependency which works as a base template for electron build configuration. There are some fields are defined there which get extended.
The fix for that is either remove electron-webpack from your project dependencies or use electron-webpack convention to manage your project.
I had a similar issue:
Application entry file "index.js" in the ".....\dist\win-unpacked\resources\app.asar" does not exist.
The fix for me was to add
main: "main.js"
in the package.json of the generated app, so .\app\package.json.
Seems like without this electron-builder 21 (electron 6) is looking for a "index.js" file.
I encountered the error when selecting the production version of my entry file which was in a different folder than the source production file.
Here is the relevant config section that got my app to build:
"build": {
"files": [
"electron-settings.json",
"package.json"
],
"extraResources": [
{
"from": "../build/backend/min",
"to": "app",
"filter": [
"**/*"
]
},
{
"from": "desktop/node_modules",
"to": "node_modules"
}
],
"mac": {
"extraResources": [
{
"from": "build/osx",
"to": "app/build/osx"
}
]
}
}
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.