node.js - Express API accessible on localhost but not on Google App Engine -
i have 2 mean (angular 4) apps , want 1 data other's api. strange thing 1 app base url same site , api. 1 returns data. other app has different base url , app not return data.
app1 (data returned)
base url: https://de***ta.appspot.com api url: https://de***ta.appspot.com/api/droplet/:id
so when serve app droplet looking gets returned in json format expect using code:
app.get('/api/droplets/:id', function(req, res) { droplets.findone({ _id: req.params.id }, function(err, droplet) { if (err) throw err; res.send(droplet); }); });
app2 (returns index.html)
base url: https://differenturl.appspot.com api url: https://de***ta.appspot.com/api/droplet/:id
so here base urls different , api url, when called http service in angular, returns index.html. assume due code in server:
app.use('*', function(req, res) { return res.sendfile(path.join(__dirname, '/dist', 'index.html')); });
but not understand why 1 api call returns index, while other 1 activated route specified.
i need know why happens , how access api external base url.
update
if run api server locally on localhost, returns data want when type url (http://localhost:8080/api/droplet/fhkssdkajfhds). when type google cloud hosted site don't it. perhaps it's issue how google cloud serves express apps?
... think it's cors problem
..could be? .can try test open api ?
so example install this: https://www.npmjs.com/package/cors , then
var cors = require('cors') var app = express() app.use(cors())
Comments
Post a Comment