Saturday, 27 May 2017

static html served by Node express won't show on iphone

My first time to try some responsive design on desktop and iPhone at the same time.

I have successfully connected my iPhone(5s) with my Mac OSX (Yosemite) on my Mac's IP address. After creating a basic Node Express server, I confirmed that the "Hello World" response shows both on my desktop Chrome and iPhone Safari.

However, when I tried to serve static html files with app.use(), I can only see it on desktop Chrome. My iPhone Safari stopped to display anything. Could you help me identify the issue, please? Thank you very much!

Here's my file structure: file structure Here's my code: server index.js:

const express = require('express');
const path = require('path');
const app = express();

app.use(express.static(path.join(__dirname, '/../client/public')));
app.get('/', (req, res) => {
  // this commented part won't work either:
  // res.status(200).sendfile(path.join(__dirname, '/../client/public/index.html'));
  res.status(200).send('I\'m from server')
});

app.listen(8080, function() {
  console.log('iphone dev app listening on port 8080');
});

Here's my index.html:

<!DOCTYPE html>
<html>
<head>
  <title>iPhone</title>
</head>
<body>
<div id="app"></div>
<script type="text/javascript" src="./assets/js/index.js"></script>
</body>
</html>

Here's my index.js on my client side:

(function() {
  let app = document.getElementById('app');
  app.innerHTML = "I'm from js";
  console.log(app);
})();



via Alison Z

No comments:

Post a Comment