Reputation: 55
I'm trying to deploy a react app to azure. I tested that my build runs, at that works fine. When I deploy my app, I get the default 'hey, node developers' page. I have then tried to add a index.js file as described on some sites, like this https://blogs.msdn.microsoft.com/waws/2017/09/08/things-you-should-know-web-apps-and-linux/#NodeHome
but now I'm getting an error...
*/home/LogFiles/2020_01_13_RD0003FF73402D_default_docker.log (https://sbwebtest.scm.azurewebsites.net/api/vfs/LogFiles/2020_01_13_RD0003FF73402D_default_docker.log)
2020-01-13T11:39:01.618020509Z 11:39:01 0|index | at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:27:21)
2020-01-13T11:39:01.619118659Z 11:39:01 0|index | at Module._compile (internal/modules/cjs/loader.js:956:30) {
2020-01-13T11:39:01.620286813Z 11:39:01 0|index | code: 'MODULE_NOT_FOUND',
2020-01-13T11:39:01.628165973Z 11:39:01 0|index | requireStack: [ '/home/site/wwwroot/index.js' ]
2020-01-13T11:39:01.629324326Z 11:39:01 0|index | }
2020-01-13T11:39:01.649097230Z 2020-01-13T11:39:01: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
2020-01-13T11:39:01.650858410Z 2020-01-13T11:39:01: PM2 log: Script /home/site/wwwroot/index.js had too many unstable restarts (16). Stopped. "errored"
2020-01-13T11:39:01.657846830Z 11:39:01 PM2 | App [index:0] exited with code [1] via signal [SIGINT]
2020-01-13T11:39:01.659306496Z 11:39:01 PM2 | Script /home/site/wwwroot/index.js had too many unstable restarts (16). Stopped. "errored"*
I have deployed using the azure tool in VS code.
Anyone know what to do ?
Upvotes: 2
Views: 1398
Reputation: 14088
First method:
The premise of this method is you have Node.js env and have installed npm tools.
1.add a file name index.js under the site/wwwroot.
index.js:
var express = require('express');
var server = express();
var options = {
index: 'index.html' //Fill path here.
};
server.use('/', express.static('/home/site/wwwroot', options));
server.listen(process.env.PORT);
2.install express:
run this command under the wwwroot directory,
npm install -save express
3.restart your app service and wait for minutes.
Second method:
1.Create a .htaccess
file under the root directory.
.htaccess
file:
DirectoryIndex public_html/index.php
2.Restart your web app and wait for minutes.
This is the structure of my web app:
Success:
Let me know if you have more doubts.
Upvotes: 2