[SOLVED] NodeJS with "http"

Hi!
I’m using V5 on the web site, and now testing nodejs.
On the local server after installing the CLI and creating the project, is started “http-server” nodejs module.
Tell me, please, how to install FW7 on a web server, where the “http” nodejs module is used?
Thank you!


I found the answer.

var express = require('express');
var app = express();

app.use('/app', express.static(__dirname + '/app'));
app.get('/', function (req, res) {
    res.sendFile(__dirname + '/app/index.html');
});

app.listen(3000);

…and changed the paths in the router

how did you solve that?

I tried different options…

…not very helpful comment for others who may also run into the same issue…

Ok, I’ll do it more accurately for all.

  1. You must setup Framework7 CLI

  2. Create new project.

  3. If you follow the instructions, in your project folder you will have the “www” folder, in this case I renamed this folder to “app”.

  4. If you look at the package.json file in the project folder, there is code:

...  
"scripts": {
    "start": "npm run serve",
    "serve": "http-server ./www/ -o -c 1 -a localhost -p 8080",
    "postinstall": "cpy './node_modules/framework7-icons/fonts/*.*' './www/fonts/'"
  },
...

This means, by default, the server is started using the “http-server” module.
I decided to use the standard “Http” module, it is used by the “ExpressJS” framework.

  1. In the project folder, create the app.js file:
var express = require('express');      /// connect express module
var app = express();

app.use('/app', express.static(__dirname + '/app'));     ///  setup work directory ( default - www)
app.get('/', function (req, res) {
    res.sendFile(__dirname + '/app/index.html');      /// go to index.html
});

app.listen(3000);    /// start server nodejs on port 3000
  1. In the project folder create .htaccess file:
PassengerNodejs    .local/bin/node  ///  type your host node path
PassengerAppRoot   /mysite.com/project_folder  /// project folder with full root path
PassengerAppType node
PassengerStartupFile app.js   /// startup file
  1. Set relative paths, edit file routes.js (app/js folder):
var routes = [
  {
    path: '/',
    url: 'app/index.html',
  },
  {
    path: '/about/',
    url: 'app/pages/about.html',
  },
...
  1. Start server with comand “node app”, or like my variant on the virtual hosting “touch tmp/restart.txt”. Enjoy!

P.S.
Everything worked for me.
Question to experts: is this right?

2 Likes