• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Please Help! Something is wrong with my NodeJS code and the Deta Space platform

LaBerginha

Well-known member
Trusted Seller
Oct 26, 2020
373
737
100
Localhost
Hi, I will show you my simplified code for you to understand me, I have a website with a frontend that I serve from the public folder using:
JavaScript:
app.use(express.static('public'));
and a backend in my index.js file with the post routes /api1 and /api2:
JavaScript:
import express from "express";
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors());
app.use(express.static('public'));
app.use(express.json());
app.post('/api1', async (req, res) => {
//code
});
app.post('/api2', async (req, res) => {
//code
});
if (process.env.NODE_ENV !== "production") {
  app.listen(PORT, () => {
    console.log(Listening on port ${PORT});
  });
}
And I'm using Deta Space, a free Heroku-like platform that is serverless to deploy to my website using NodeJS. This is my current Deta configuration (Spacefile):
Code:
v: 0
micros:
  - name: xdchk
    src: .
    engine: nodejs16
    primary: true
    public: true

What I want is that only the index.html and the frontend css/js files are public, but the /api1 and /api2 paths are not public, only for my own web.
This is the documentation on how to configure routes:
 
Thanks friend, I had already tried that solution, the problem with it was that the token is always the same and therefore if you had the token you could access the API without problems. Do you have any other idea in mind? If you speak Spanish I could explain the problem better. @alexmisaila
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock