Postingan lainnya
Cara agar rest api kita dapat di akses di port 80
Mohon pencerahannya, saya ada tugas dari kantor terkait integrasi API,engine yang digunakan berdasar dari nodejs, saya diminta agar service yang dibuat dijalankan di port 80, sedangkan ketika saya coba jalankan di port 80 ketika saya cek di iptables service nya bisa listen, saya tes telnet ip 80 pun connected, tapi pas di cek testing di rest client malah Time Out, saya cari2 di forum memang sulit untuk service berjalan di port 80 dan amannya di port 3000, pertanyaannya, apakah bisa apabila service di jalankan di port selain 80 (contoh :3000), namun client tetap mengakses ke port 80?
3 Jawaban:
coba cek <a href='https://stackoverflow.com/questions/20907591/cant-connect-to-port-error-with-node'>jawaban stackoverflow</a> ini ya, masalahnya apa ya kalau tidak run di port 80? coba dinego aja kalau tidak ada masalah khusus, bisa pakai file .env (environment) jadi bisa dengan mudah ganti port termasuk saat didpeloy nanti
<div>API, misal running : port 3000<br>Documentroot, misal : /home/user/public_html/backend<br>Web server, misal : apache<br><br>Tinggal buat file .htaccess di public_html/backend, kemudian tulis seperti ini :<br><br></div><pre>DirectoryIndex disabled RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ http://%{HTTP_HOST}:3000/$1 [P,L] RewriteRule ^$ http://%{HTTP_HOST}:3000/ [P,L]</pre><div><br>Contoh hasil :<br><figure data-trix-attachment="{"contentType":"image/png","filename":"localhost-api.png","filesize":34823,"height":436,"url":"https://i.ibb.co/WVdXs6q/localhost-api.png","width":888}" data-trix-content-type="image/png" data-trix-attributes="{"presentation":"gallery"}" class="attachment attachment--preview attachment--png"><img src="https://i.ibb.co/WVdXs6q/localhost-api.png" width="888" height="436"><figcaption class="attachment__caption"><span class="attachment__name">localhost-api.png</span></figcaption></figure></div>
<div>Bisa diakses juga via postman, dengan authorization header + support juga kalau mau https asal ada SSL nya.<figure data-trix-attachment="{"contentType":"image/png","filename":"image.png","filesize":162965,"height":1432,"url":"https://i.ibb.co/sbdV6ZK/image.png","width":1828}" data-trix-content-type="image/png" data-trix-attributes="{"presentation":"gallery"}" class="attachment attachment--preview attachment--png"><img src="https://i.ibb.co/sbdV6ZK/image.png" width="1828" height="1432"><figcaption class="attachment__caption"><span class="attachment__name">image.png</span></figcaption></figure></div><div><figure data-trix-attachment="{"contentType":"image/png","filename":"image.png","filesize":644397,"height":1860,"url":"https://i.ibb.co/PwMgwZx/image.png","width":1844}" data-trix-content-type="image/png" data-trix-attributes="{"presentation":"gallery"}" class="attachment attachment--preview attachment--png"><img src="https://i.ibb.co/PwMgwZx/image.png" width="1844" height="1860"><figcaption class="attachment__caption"><span class="attachment__name">image.png</span></figcaption></figure></div>