Ionic as a web server

I have an Ionic project, and I want it to work as if it is a web server (say mamp + php).

Since Ionic is able to display the project in a local browser (using ion feed), I am sure that it can do it. I have a simple ovh server.

How can i do this?

+6
source share
2 answers

You will need to send all your project files (www folder) and dependencies to the web server.

You can try.

Local

$ cd [ionic project] $ ionic platform add browser $ cd [ionic project]/platforms/browser/ 

and move the www folder to the [webapp] folder on the server.

Server

On your server:

1.Install Node.js

  1. Install connect and serve-static

    $ cd [webapp] $ npm install connect serve-static

  2. Create server.js file

     var connect = require('connect'); var serveStatic = require('serve-static'); connect().use(serveStatic(__dirname)).listen(8080) 
  3. Start service

    $ node server.js &

Browser

Now you can go to http: // yourdomain: 8080 / index.html

I hope this can help you :)

+15
source

Excellent answer Carlos, it was very helpful. If you connect to your server via ssh, the node server will stop working when you exit the ssh session. To avoid this problem, run "node forever start server.js" instead of "node server.js &".

-1
source

Source: https://habr.com/ru/post/987368/


All Articles