Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use relative url instead of static urls #1078

Merged
merged 6 commits into from
Jun 27, 2018

Conversation

popojargo
Copy link
Member

@popojargo popojargo commented Apr 30, 2018

Overview

  • Add helper functions to get API url and Server urls
  • Fix some url who were not using relative urls
  • Fix documentation urls that were using _utils instead of relative
  • Update test according to change
  • Changed default configuration in settings.json

Testing recommendations

I used a express pouchdb setup.

  1. Create a folder 👍
  2. In that folder create a package.json
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "test.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.3",
    "express-pouchdb": "^4.0.0",
    "morgan": "^1.4.0",
    "pouchdb": "^6.4.3"
  }
}
  1. Create a test.js
var express = require('express')
    , app = express()
    , PouchDB = require('pouchdb')
    , logger = require('morgan')
;

app.use(logger("tiny"));
app.get('/', function (req, res, next) {
    res.send('Welcome Traveler!  <a href="/db/_utils/">Fauxton?</a>');
});
//app.use('/express-pouchdb', require('express-pouchdb')(PouchDB));
app.use('/db', require('express-pouchdb')(PouchDB));
app.listen(3000);
  1. Install depencies with npm install

  2. You need to edit node_modules/express-pouchdb/lib/routes/fauxton.js and change the exports for:

module.exports = function (app) {
  app.get('/_utils/', function (req, res) {
    // We want to force /_utils to /_utils/ as this is the CouchDB behavior
    // https://git.io/vDMOD#L78
    // https://git.io/vDMOQ#L974
    if (req.originalUrl === '/_utils') {
      res.redirect(301, '/_utils/');
    } else {
      res.sendFile(path.normalize(FAUXTON_PATH + '/index.html'));
    }
  });

  app.use('/_utils/', express.static(FAUXTON_PATH));
};
  1. Make a fauxton release (grunt release) and copy the release to node_modules/pouchdb-fauxton/www

  2. You need to replace in the index.html of the release (dashboard -> ./dashboard)

  3. You should be good 💃

GitHub issue number

#944

Checklist

  • Code is written and works correctly;
  • Changes are covered by tests;
  • Documentation reflects the changes;
  • Update rebar.config.script with the correct tag once a new Fauxton release is made

app/constants.js Outdated
MANGO_INDEX: '/_utils/docs/intro/api.html#documents',
MANGO_SEARCH: '/_utils/docs/intro/api.html#documents',
CHANGES: '/_utils/docs/api/database/changes.html?highlight=changes#post--db-_changes'
GENERAL:'./docs/intro/api.html#documents',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably use the getServerUrl here to be more consistent but I had trouble with circular dependencies 😞

app/helpers.js Outdated
};

Helpers.getServerUrl = endpointRoute => {
if (endpointRoute.startsWith("/")) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove the first slash to avoid having //_session

@@ -27,7 +27,7 @@
},
"app": {
"root": "/",
"host": "../..",
"host": "./",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In dev, we have a proxy at the root

@@ -42,7 +42,7 @@
},
"app": {
"root": "/",
"host": "../..",
"host": "../",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a release, Fauxton should be at /_utils/ so we have to get back one "folder".

@popojargo popojargo changed the title WIP: Use relative url instead of static urls Use relative url instead of static urls May 1, 2018
@wohali
Copy link
Member

wohali commented Jun 26, 2018

+1 on this if you can rebase it

* Add helper functions to get API url and Server urls
* Fix some url who were not using relative urls
* Fix documentation urls that were using _utils instead of relative
* Update test according to change
* Changed default configuration in settings.json
Copy link
Contributor

@Antonio-Maranhao Antonio-Maranhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@popojargo
Copy link
Member Author

I will compile Couch with this branch and see if there's not breaking change. Then I'll merge when Travis goes green

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants