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:
and a backend in my index.js file with the post routes /api1 and /api2:
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):
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:
JavaScript:
app.use(express.static('public'));
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});
});
}
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: