Comments (5)
Hey, if I had to guess you're missing 1 or more required inputs when creating a server. Try the following snippet below and see if anything changes:
router.get('/newserver', checkAuth, async function(req, res) {
const pteroData = await client.getUserByEmail(req.user.email);
const server = new Nodeactyl.ServerBuilder()
.setServerName(req.query.name)
.setServerOwner(pteroData.attributes.id)
.setServerEgg(parseInt(req.query.egg))
.setServerLimitsJson({
memory: parseInt(req.query.ram),
disk: parseInt(req.query.disk),
cpu: parseInt(req.query.cpu),
io: 500,
swap: 0,
})
.createServer(client).then(response => {
console.log(response);
res.redirect('/shop');
});
});
I'm thinking the issue lies in the .setServerLimitsJson argument you were giving (should be an object not a string). I also removed the separate server.function() calls and chained them together instead which is part of what makes the ServerBuilder so powerful. Let me know if this helps.
from nodeactyl.
I got this error when I copy pasted your code:
.setServerOwner(pteroData.attributes.id)
^
TypeError: Cannot read properties of undefined (reading 'setServerOwner')
So I changed it a bit to this:
router.get('/newserver', checkAuth, async function(req, res) {
const pteroData = await client.getUserByEmail(req.user.email);
const server = new Nodeactyl.ServerBuilder()
server.setServerName(req.query.name)
server.setServerLimitsJson({
memory: parseInt(req.query.ram),
disk: parseInt(req.query.disk),
cpu: parseInt(req.query.cpu),
io: 500,
swap: 0,
})
server.setServerOwner(pteroData.attributes.id)
server.setServerEgg(parseInt(req.query.egg))
server.createServer(client).then(response => {
console.log(response);
res.redirect('/shop');
});
});
and I still am getting the same 422
error.
from nodeactyl.
Hi, the following mocked example worked successfully for me:
(async () => {
const req = {
user: {
email: 'email of existing user',
},
query: {
name: 'My new server',
ram: 512,
disk: 512,
cpu: 100,
egg: 5,
},
};
const pteroData = await client.getUserByEmail(req.user.email);
const server = new Nodeactyl.ServerBuilder();
server.setServerName(req.query.name);
server.setServerLimitsJson({
memory: parseInt(req.query.ram),
disk: parseInt(req.query.disk),
cpu: parseInt(req.query.cpu),
io: 500,
swap: 0,
});
server.setServerOwner(pteroData.attributes.id);
server.setServerEgg(parseInt(req.query.egg));
server.createServer(client).then(response => {
console.log(response);
});
})();
The only changes I made to the code in your latest reply was removing the route and mocking the data you are pulling from the request object in order to ensure the code to create the server and the library were working successfully.
I would suggest investigating the code specific to your application that you posted in your last reply. If I had to guess one or more of the values you are trying to pull from req are not returning what you want. Ensure that the user you are retrieving by email is being found successfully and that all the other parts you are setting (name, limits, egg) are all being set to the values you expect them to be set to.
from nodeactyl.
Hi, the following mocked example worked successfully for me:
(async () => { const req = { user: { email: 'email of existing user', }, query: { name: 'My new server', ram: 512, disk: 512, cpu: 100, egg: 5, }, }; const pteroData = await client.getUserByEmail(req.user.email); const server = new Nodeactyl.ServerBuilder(); server.setServerName(req.query.name); server.setServerLimitsJson({ memory: parseInt(req.query.ram), disk: parseInt(req.query.disk), cpu: parseInt(req.query.cpu), io: 500, swap: 0, }); server.setServerOwner(pteroData.attributes.id); server.setServerEgg(parseInt(req.query.egg)); server.createServer(client).then(response => { console.log(response); }); })();The only changes I made to the code in your latest reply was removing the route and mocking the data you are pulling from the request object in order to ensure the code to create the server and the library were working successfully.
I would suggest investigating the code specific to your application that you posted in your last reply. If I had to guess one or more of the values you are trying to pull from req are not returning what you want. Ensure that the user you are retrieving by email is being found successfully and that all the other parts you are setting (name, limits, egg) are all being set to the values you expect them to be set to.
I tested your code and got the following as an error:
(node:1276674) UnhandledPromiseRejectionWarning: 422
(node:1276674) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
from nodeactyl.
I tested the example again to be sure and it does in fact create a server and return the data without a 422 error. I am using the latest version of Nodeactyl (3.2.1). In the context of the example I posted it must be made sure that you change the req.user.email field with a valid user's email and the req.query.egg field with a valid egg id from the panel you are testing on.
const Nodeactyl = require('nodeactyl');
const client = new Nodeactyl.NodeactylApplication('your valid panel url', 'your valid api key');
(async () => {
const req = {
user: {
email: 'existing user email',
},
query: {
name: 'My new server',
ram: 512,
disk: 512,
cpu: 100,
egg: 5,
},
};
const pteroData = await client.getUserByEmail(req.user.email);
const server = new Nodeactyl.ServerBuilder();
server.setServerName(req.query.name);
server.setServerLimitsJson({
memory: parseInt(req.query.ram),
disk: parseInt(req.query.disk),
cpu: parseInt(req.query.cpu),
io: 500,
swap: 0,
});
server.setServerOwner(pteroData.attributes.id);
server.setServerEgg(parseInt(req.query.egg));
server.createServer(client).then(response => {
console.log(response);
});
})();
This is the full example I used, including the declaration/initialization of the client variable (which must be set by you for testing).
from nodeactyl.
Related Issues (20)
- Issue HOT 1
- createServer returns undefined HOT 1
- Help me with this error HOT 1
- API Endpoint to consume console log HOT 1
- TypeError: Cannot read property 'status' of undefined HOT 1
- Create server function not doing anything HOT 1
- panel support
- dont steal packages HOT 1
- dont steal packages asshole :) HOT 1
- Not sure how /api/client/servers/UUID/startup/* works HOT 2
- callback is not a function HOT 1
- 403 Error while getAllServer HOT 3
- Docs Website Down HOT 2
- Proof It's Me
- Status not updating HOT 2
- Are there types for this project. HOT 2
- Assign additional allocations HOT 2
- Make ServerBuilder return this for methods HOT 1
- getServerDetails doesnt return ports/Allocations HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodeactyl.