I receive HTML page when send a request to Node app

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});
});

The waking up page is to symbolize that the project is setting up. Check the logs for any info.

1 Like

Sadly but it’s not. I can certainly go to the page using my Chrome browser. But can’t do the same thing with https request since it’s always return the “waking-up” html

This behaviour started a bit after pinging was banned, Glitch thinks the request from your local server looks similar to “keep awake” type requests.

1 Like

Is there a way to get around it? I’m hooking the call to githooks so it’ll certainly by local server. If not, then probably glitch is not the correct platform :frowning:

Try setting a User-Agent header with the request. There’s some filtering going on as mishavee said.

what kind of User-Agent would you suggest? Should I just go to Postman and copy what I have been using to send the request there?

I use the name and version of my project. I figure this is something Glitch uses to filter out compliant and non-compliant projects, so I’m trying to send something specific.

There was a post by one of the Glitch people about opting out of the waking up screen.
(I think)

This may sound a little dirty, but try setting the user agent of the request to that of a computer.

For example, I am running Chrome on ChromeOS, and my user agent looks like:
Mozilla/5.0 (X11; CrOS x86_64 12739.105.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.158 Safari/537.36

Setting the user agent is quite easy, depending on what library you use. cURL is probably the best, if you use the CLI you can try something like:

curl -A "your user agent here" https://project.glitch.me