Ionic as a web server
Asked Answered
I

2

8

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 a project in browser localy (using ionic serve), I am pretty sure it is able to do that. I have a simple ovh server.

How could I do that ?

Instar answered 17/5, 2015 at 12:38 Comment(2)
Copy the WWW folder to your webserver. Ionic serve creates a node.js webserver on port 8100 ( if I remember well)Titbit
@Titbit This is right !Instar
S
19

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

You can try.

Local

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

and move your www folder to your server [webapp] folder.

Server

In 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. Run serve

    $ node server.js &

Browser

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

I hope this can help you :)

Softy answered 17/5, 2015 at 19:20 Comment(1)
Why the "add browser" is necessary?Folia
S
0

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

Sefton answered 30/3, 2016 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.