Hey guys, so I’m setting up a free glitch server to host my API. However, regardless of whether I can easily head to browser or Postman to send a request and get a correct result, I can’t seem to do the same thing with my local node application. It always returns a “waking-up” HTML page even though it’s not asleep. Can you help me out?
Local
const https = require(‘https’);
const req = https.request({
hostname: 'xxx.glitch.me', path: '/api/change-issue', method: 'POST', headers: { 'Content-Type': 'application/json', },
}, (res) => {
res.on('data', (data) => { console.log(`${data} data`); }); res.on('end', () => { process.exit(0); });
});
req.on(‘error’, (e) => {
console.error(e); process.exit(1);
});
req.write(‘’);
req.end();
Glitch App
const app = express();
const port = process.env.PORT || 3000;
app.use(express.static(‘assets’));
app.use(express.json());
app.get(‘/’, (_req, res) => {
res.sendFile(path.join(__dirname, ‘assets’, ‘view’, ‘index.html’));
});app.get(‘/add’, (_req, res) => {
res.sendFile(path.join(__dirname, ‘assets’, ‘view’, ‘add.html’));
});app.get(‘/login’, (_req, res) => {
res.sendFile(path.join(__dirname, ‘assets’, ‘view’, ‘login.html’));
});app.post(‘/api/change-issue’, async (req, res) => {
res.status(200).send(‘Successfully change branch on xxx’);
});app.listen(port, () => {
console.info(Example app listening at http://localhost:${port}
);
});