Reputation: 895
I have developed a NestJS Server application. NestJs is a node server running with express written in TypeScript.
Now I want to deploy the application on my rapsberry pi. However, I'm only able to access the server from localhost. If I try to access from a different client no content is returned. (The "^C" in the picture is only the cancel sign ;D)
I already set the hostname to 0.0.0.0
. What else can I do?
# /src/main.ts
import {NestFactory} from '@nestjs/core';
import {AppModule} from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
await app.listen(3001, '0.0.0.0');
}
Upvotes: 6
Views: 15601
Reputation: 1
const express = require('express');
const app = express();
const port = 3000; // Choose your desired port
app.get('/', (req, res) => {
res.send('Hello, World!');
});
// Change from 'localhost' to '0.0.0.0'
app.listen(port, '0.0.0.0', () => {
console.log(`Server is listening on port ${port}`);
});
Upvotes: -1
Reputation: 453
You must open firewall port and service, see below (this works for CentOS box):
#add port
sudo firewall-cmd --add-port=3001/tcp --permanent
# add service
sudo firewall-cmd --permanent --add-service=http
# reload !!! IMPORTANT !!!
sudo firewall-cmd --reload
Upvotes: 0