webonerds
webonerds

Reputation: 46

How I can use ionic 2 app as website on production server ?

I would like to know if any specific steps to deploy ionic 2 project on production server.

T tried running ionic serve on production server but when i tried call api its saying cors( allow origin issue).

Please help .

Thanks

Upvotes: 2

Views: 4828

Answers (3)

Gary
Gary

Reputation: 421

it works for me. I have full control of an apache server that does proxying for the domains.

I point my desktop version to the webpacked dist/ folder and the mobile version at the www/ directory leftover from ionic serve.

Proxy /api/ to my pm2/node app running on port 3080 in my case.

Point all my node server requests to http://MYAPP.com/api/ or http://mobile.MYAPP.com/api/ .. Static content is available at http://MYAPP.com/ or http://mobile.MYAPP.com/

<Directory "/usr/local/www/node/MYAPP/dist">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<Directory "/usr/local/www/node/MYAPP/www">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<VirtualHost *:80>
    ServerName mobile.MYAPP.com
    DocumentRoot "/usr/local/www/node/MYAPP/www/"
    ProxyPass /api/ http://localhost:3080/
    ProxyPassReverse /api/ http://localhost:3080/
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/usr/local/www/node/MYAPP/dist/"
    ProxyPass /api/ http://localhost:3080/
    ProxyPassReverse /api/ http://localhost:3080/
</VirtualHost>

Upvotes: 1

TheBrockEllis
TheBrockEllis

Reputation: 979

At this moment, with Ionic 2 beta 10, I believe running an Ionic app as a 'progressive web app' is not possible. However, the team has stated their intention to eventually allow Ionic 2 apps to be submitted the app stores as well as run on a web server to be accessed via web browser.

This ionicforum answer from a moderator states that Ionic 2 apps cannot be hosted as stand-alone web apps yet, but that the functionality is "in the workds".

Take a look at this blog post from Ionic on further reading about Progressive Web Apps and how they are working toward getting Ionic apps to be PWAs.

Upvotes: 0

Denko Mancheski
Denko Mancheski

Reputation: 2709

The cors problem needs to be resolved on the server, so the server will allow cors. If you are using node you can use the cors package and than call app.use(cors()). If not, you need to find how to enable cors on your production server. Ionic can block requests if it runs in cordova (thats why you can specify a whitelist using the whitelist plugin that ionic provides, but I think that since you are running it as a website, the whitelist plugin cannot help much.

To test how your website works on your production server you can download the cors plugin for chrome, enable it and check if everything works fine :)

Upvotes: 1

Related Questions