Skip to content

Commit

Permalink
Merge pull request #1747 from specklesystems/gergo/noLocalhost
Browse files Browse the repository at this point in the history
fix(monorepo): make sure to use 127.0.0.1 instead of localhost
  • Loading branch information
gjedlicska authored Aug 6, 2023
2 parents 10d9a64 + f202d0e commit e019864
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .graphqlrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema: 'http://localhost:3000/graphql'
schema: 'http://127.0.0.1:3000/graphql'
extensions:
languageService:
# Cause it's busted
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-speckle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
start_period: 90s
environment:
# TODO: Change this to the URL of the speckle server, as accessed from the network
CANONICAL_URL: 'http://localhost'
CANONICAL_URL: 'http://127.0.0.1'

# TODO: Change this to a unique secret for this server
SESSION_SECRET: 'TODO:Replace'
Expand Down
2 changes: 1 addition & 1 deletion packages/fileimport-service/ifc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function parseAndCreateCommit({

const userToken = process.env.USER_TOKEN

const serverBaseUrl = process.env.SPECKLE_SERVER_URL || 'http://localhost:3000'
const serverBaseUrl = process.env.SPECKLE_SERVER_URL || 'http://127.0.0.1:3000'
logger.info(`Creating commit for object (${id}), with message "${message}"`)
const response = await fetch(serverBaseUrl + '/graphql', {
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion packages/fileimport-service/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = require('knex')({
connection: {
application_name: 'speckle_fileimport_service',
connectionString:
process.env.PG_CONNECTION_STRING || 'postgres://speckle:speckle@localhost/speckle'
process.env.PG_CONNECTION_STRING || 'postgres://speckle:speckle@127.0.0.1/speckle'
},
pool: { min: 0, max: 1 }
// migrations are in managed in the server package
Expand Down
2 changes: 1 addition & 1 deletion packages/fileimport-service/obj/import_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def import_obj():
# Commit

client = SpeckleClient(
host=os.getenv("SPECKLE_SERVER_URL", "localhost:3000"), use_ssl=False
host=os.getenv("SPECKLE_SERVER_URL", "127.0.0.1:3000"), use_ssl=False
)
client.authenticate_with_token(os.environ["USER_TOKEN"])

Expand Down
2 changes: 1 addition & 1 deletion packages/fileimport-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"node": "^18.17.0"
},
"scripts": {
"dev": "cross-env POSTGRES_URL=postgres://speckle:speckle@localhost/speckle NODE_ENV=development LOG_PRETTY=true SPECKLE_SERVER_URL=http://localhost:3000 nodemon --no-experimental-fetch ./src/daemon.js",
"dev": "cross-env POSTGRES_URL=postgres://speckle:speckle@127.0.0.1/speckle NODE_ENV=development LOG_PRETTY=true SPECKLE_SERVER_URL=http://127.0.0.1:3000 nodemon --no-experimental-fetch ./src/daemon.js",
"parse:ifc": "node --no-experimental-fetch ./ifc/import_file.js ./ifc/ifcs/steelplates.ifc 33763848d6 2e4bfb467a main File upload: steelplates.ifc",
"lint": "eslint . --ext .js,.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/fileimport-service/stl/import_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def import_stl():
# Commit

client = SpeckleClient(
host=os.getenv("SPECKLE_SERVER_URL", "localhost:3000"), use_ssl=False
host=os.getenv("SPECKLE_SERVER_URL", "127.0.0.1:3000"), use_ssl=False
)
client.authenticate_with_token(os.environ["USER_TOKEN"])

Expand Down
49 changes: 48 additions & 1 deletion packages/frontend-2/lib/common/generated/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@ export type ActivityCollection = {
totalCount: Scalars['Int'];
};

export type AdminQueries = {
__typename?: 'AdminQueries';
projectList: ProjectCollection;
serverStatistics: ServerStatistics;
userList: AdminUserList;
};


export type AdminQueriesProjectListArgs = {
cursor?: InputMaybe<Scalars['String']>;
limit?: Scalars['Int'];
orderBy?: InputMaybe<Scalars['String']>;
query?: InputMaybe<Scalars['String']>;
visibility?: InputMaybe<Scalars['String']>;
};


export type AdminQueriesUserListArgs = {
cursor?: InputMaybe<Scalars['String']>;
limit?: Scalars['Int'];
query?: InputMaybe<Scalars['String']>;
role?: InputMaybe<ServerRole>;
};

export type AdminUserList = {
__typename?: 'AdminUserList';
cursor?: Maybe<Scalars['String']>;
items: Array<LimitedUser>;
totalCount: Scalars['Int'];
};

export type AdminUsersListCollection = {
__typename?: 'AdminUsersListCollection';
items: Array<AdminUsersListItem>;
Expand Down Expand Up @@ -1581,11 +1612,16 @@ export type Query = {
_?: Maybe<Scalars['String']>;
/** Gets the profile of the authenticated user or null if not authenticated */
activeUser?: Maybe<User>;
/** All the streams of the server. Available to admins only. */
admin: AdminQueries;
/**
* All the streams of the server. Available to admins only.
* @deprecated use admin.projectList instead
*/
adminStreams?: Maybe<StreamCollection>;
/**
* Get all (or search for specific) users, registered or invited, from the server in a paginated view.
* The query looks for matches in name, company and email.
* @deprecated use admin.UserList instead
*/
adminUsers?: Maybe<AdminUsersListCollection>;
/** Gets a specific app from the server. */
Expand Down Expand Up @@ -1615,6 +1651,7 @@ export type Query = {
*/
projectInvite?: Maybe<PendingStreamCollaborator>;
serverInfo: ServerInfo;
/** @deprecated use admin.serverStatistics instead */
serverStats: ServerStats;
/**
* Returns a specific stream. Will throw an authorization error if active user isn't authorized
Expand Down Expand Up @@ -1834,6 +1871,7 @@ export type ServerInfo = {
canonicalUrl?: Maybe<Scalars['String']>;
company?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
guestModeEnabled: Scalars['Boolean'];
inviteOnly?: Maybe<Scalars['Boolean']>;
name: Scalars['String'];
roles: Array<Maybe<Role>>;
Expand All @@ -1846,6 +1884,7 @@ export type ServerInfoUpdateInput = {
adminContact?: InputMaybe<Scalars['String']>;
company?: InputMaybe<Scalars['String']>;
description?: InputMaybe<Scalars['String']>;
guestModeEnabled?: InputMaybe<Scalars['Boolean']>;
inviteOnly?: InputMaybe<Scalars['Boolean']>;
name: Scalars['String'];
termsOfService?: InputMaybe<Scalars['String']>;
Expand All @@ -1866,9 +1905,17 @@ export type ServerInviteCreateInput = {
export enum ServerRole {
ServerAdmin = 'SERVER_ADMIN',
ServerArchivedUser = 'SERVER_ARCHIVED_USER',
ServerGuest = 'SERVER_GUEST',
ServerUser = 'SERVER_USER'
}

export type ServerStatistics = {
__typename?: 'ServerStatistics';
totalPendingInvites: Scalars['Int'];
totalProjectCount: Scalars['Int'];
totalUserCount: Scalars['Int'];
};

export type ServerStats = {
__typename?: 'ServerStats';
/** An array of objects currently structured as { created_month: Date, count: int }. */
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend-2/lib/common/helpers/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ export function mapServerRoleToValue(graphqlServerRole: ServerRole): ServerRoles
return Roles.Server.Admin
case ServerRole.ServerArchivedUser:
return Roles.Server.ArchivedUser
case ServerRole.ServerGuest:
return Roles.Server.Guest
}
}
6 changes: 3 additions & 3 deletions packages/frontend/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"request": "launch",
"reAttach": true,
"name": "Launch localhost",
"url": "http://localhost:3000",
"url": "http://127.0.0.1:3000",
"webRoot": "${workspaceFolder}",
"sourceMaps": true,
"trace": true,
Expand All @@ -21,10 +21,10 @@
]
},
{
"type": "pwa-chrome",
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"url": "http://127.0.0.1:3000",
"webRoot": "${workspaceFolder}",
"sourceMaps": true,
"trace": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/apollo.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
client: {
service: 'speckle-server',
url: 'http://localhost:3000/graphql',
url: 'http://127.0.0.1:3000/graphql',
includes: ['src/**/*.{js,jsx,ts,tsx,vue,gql}']
}
}
6 changes: 3 additions & 3 deletions packages/preview-service/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ build:

run:
docker run -it --rm --net=host \
-e PG_CONNECTION_STRING="postgres://speckle:speckle@localhost/speckle" \
-e PG_CONNECTION_STRING="postgres://speckle:speckle@127.0.0.1/speckle" \
preview-service

run-release:
docker run -it --rm --net=host \
-e PG_CONNECTION_STRING="postgres://speckle:speckle@localhost/speckle" \
-e PG_CONNECTION_STRING="postgres://speckle:speckle@127.0.0.1/speckle" \
speckle/speckle-preview-service:v2.3.3


small:
docker build -t small-preview-service ../.. -f Dockerfile.small
docker run -it --rm --net=host -e PG_CONNECTION_STRING="postgres://speckle:speckle@localhost/speckle" small-preview-service bash
docker run -it --rm --net=host -e PG_CONNECTION_STRING="postgres://speckle:speckle@127.0.0.1/speckle" small-preview-service bash
2 changes: 1 addition & 1 deletion packages/preview-service/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = require('knex')({
connection: {
application_name: 'speckle_preview_service',
connectionString:
process.env.PG_CONNECTION_STRING || 'postgres://speckle:speckle@localhost/speckle'
process.env.PG_CONNECTION_STRING || 'postgres://speckle:speckle@127.0.0.1/speckle'
},
pool: { min: 0, max: 2 }
// migrations are in managed in the server package
Expand Down
2 changes: 1 addition & 1 deletion packages/preview-service/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ After the viewer web page is up to date, run the preview service with:
yarn dev
```

This will use the default dev DB connection of `postgres://speckle:speckle@localhost/speckle`. You can pass the environment variable `PG_CONNECTION_STRING` to change this to a different DB.
This will use the default dev DB connection of `postgres://speckle:speckle@127.0.0.1/speckle`. You can pass the environment variable `PG_CONNECTION_STRING` to change this to a different DB.

## Deployment notes

Expand Down
4 changes: 2 additions & 2 deletions packages/server/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ONBOARDING_STREAM_CACHE_BUST_NUMBER=1
# If you specify a user and password, do not specify the protocol in the
# POSTGRES_URL variable.
# These defaults are set for the local development environment
POSTGRES_URL="localhost"
POSTGRES_URL="127.0.0.1"
# this overrides the default root user in the postgres instance
POSTGRES_USER="speckle"
# this sets the root user password in the postgres instance
Expand Down Expand Up @@ -123,7 +123,7 @@ STRATEGY_LOCAL=true
# If your frontend is served in dev from somewhere else,
# this is going to help out :)
############################################################
# FRONTEND_HOST=localhost
# FRONTEND_HOST=127.0.0.1
# FRONTEND_PORT=8081

SPECKLE_AUTOMATE_URL="http://127.0.0.1:3030"
4 changes: 2 additions & 2 deletions packages/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export async function shutdown(): Promise<void> {
const shouldUseFrontendProxy = () => process.env.NODE_ENV === 'development'

async function createFrontendProxy() {
const frontendHost = process.env.FRONTEND_HOST || 'localhost'
const frontendHost = process.env.FRONTEND_HOST || '127.0.0.1'
const frontendPort = process.env.FRONTEND_PORT || 8080
const { createProxyMiddleware } = await import('http-proxy-middleware')

Expand Down Expand Up @@ -388,7 +388,7 @@ export async function startHttp(
app.use(await createFrontendProxy())

startupLogger.info('✨ Proxying frontend-1 (dev mode):')
startupLogger.info(`👉 main application: http://localhost:${port}/`)
startupLogger.info(`👉 main application: http://127.0.0.1:${port}/`)
}

// Production mode
Expand Down
4 changes: 2 additions & 2 deletions packages/server/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ const config = {
test: {
...commonConfig,
connection: {
connectionString: connectionUri || 'postgres://localhost/speckle2_test',
connectionString: connectionUri || 'postgres://127.0.0.1/speckle2_test',
application_name: 'speckle_server'
}
},
development: {
...commonConfig,
connection: {
connectionString: connectionUri || 'postgres://localhost/speckle2_dev',
connectionString: connectionUri || 'postgres://127.0.0.1/speckle2_dev',
application_name: 'speckle_server'
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/server/modules/auth/tests/apps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Services @apps-services', () => {
name: 'test application',
public: true,
scopes: [Scopes.Streams.Read],
redirectUrl: 'http://localhost:1335'
redirectUrl: 'http://127.0.0.1:1335'
})

expect(res).to.have.property('id')
Expand All @@ -88,7 +88,7 @@ describe('Services @apps-services', () => {
})

it('Should fail to register an app with no scopes', async () => {
await createApp({ name: 'test application2', redirectUrl: 'http://localhost:1335' })
await createApp({ name: 'test application2', redirectUrl: 'http://127.0.0.1:1335' })
.then(() => {
throw new Error('this should have been rejected')
})
Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/cli/commands/bull/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const command: CommandModule<unknown, { testQueueId: string }> = {
app.listen(PORT, () => {
cliLogger.info(`Running on ${PORT}...`)
cliLogger.info(
`For the UI, open http://localhost:${PORT}/, and make sure Redis is running`
`For the UI, open http://127.0.0.1:${PORT}/, and make sure Redis is running`
)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/core/services/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
async getServerInfo() {
const serverInfo = await Info().select('*').first()
serverInfo.version = process.env.SPECKLE_SERVER_VERSION || 'dev'
serverInfo.canonicalUrl = process.env.CANONICAL_URL || 'localhost'
serverInfo.canonicalUrl = process.env.CANONICAL_URL || '127.0.0.1'
return serverInfo
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,7 @@ export type ServerInfo = {
canonicalUrl?: Maybe<Scalars['String']>;
company?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
guestModeEnabled: Scalars['Boolean'];
inviteOnly?: Maybe<Scalars['Boolean']>;
name: Scalars['String'];
roles: Array<Maybe<Role>>;
Expand All @@ -1886,6 +1887,7 @@ export type ServerInfoUpdateInput = {
adminContact?: InputMaybe<Scalars['String']>;
company?: InputMaybe<Scalars['String']>;
description?: InputMaybe<Scalars['String']>;
guestModeEnabled?: InputMaybe<Scalars['Boolean']>;
inviteOnly?: InputMaybe<Scalars['Boolean']>;
name: Scalars['String'];
termsOfService?: InputMaybe<Scalars['String']>;
Expand All @@ -1906,6 +1908,7 @@ export type ServerInviteCreateInput = {
export enum ServerRole {
ServerAdmin = 'SERVER_ADMIN',
ServerArchivedUser = 'SERVER_ARCHIVED_USER',
ServerGuest = 'SERVER_GUEST',
ServerUser = 'SERVER_USER'
}

Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/emails/utils/transporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const createJsonEchoTransporter = () => createTransport({ jsonTransport: true })
const initSmtpTransporter = async () => {
try {
const smtpTransporter = createTransport({
host: process.env.EMAIL_HOST || 'localhost',
host: process.env.EMAIL_HOST || '127.0.0.1',
port: parseInt(process.env.EMAIL_PORT || '587'),
secure: process.env.EMAIL_SECURE === 'true',
auth: {
Expand Down
8 changes: 4 additions & 4 deletions packages/server/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ After you have PostgreSQL and Redis running, in the `packages/server` folder:
- If you have a custom setup, open and edit the `.env` & `.env.test` files, filling in the required variables,
- run `yarn install`,
- finally `yarn dev`,
- check `localhost:3000/graphql` out!
- check `127.0.0.1:3000/graphql` out!

## Developing

Expand Down Expand Up @@ -72,18 +72,18 @@ Use `yarn cli bull monitor` to serve a Web UI for our Bull queues (e.g. Notifica

### Frontend

- In **development** mode, the Speckle Server will proxy the frontend from `localhost:3000` to `localhost:8080`.
- In **development** mode, the Speckle Server will proxy the frontend from `127.0.0.1:3000` to `127.0.0.1:8080`.
If you don't see anything, ensure you've run `yarn dev` in the frontend package.

- In **production** mode, the frontend is served by an `nginx` container that proxy server requests to the server (depending on the requested path). For more information about making a production deployment, check out [our detailed guide](https://speckle.guide/dev/server-setup.html)

### GraphIQL

A GraphIQL app is available for authenticated api exploration at `localhost:3000/explorer`. Note that for the authentication flow to work, you need to have the frontend running first.
A GraphIQL app is available for authenticated api exploration at `127.0.0.1:3000/explorer`. Note that for the authentication flow to work, you need to have the frontend running first.

### GraphQL Playground

For non-authenticated api exploration, you can use the Graphql Playground which is available by default at `localhost:3000/graphql`.
For non-authenticated api exploration, you can use the Graphql Playground which is available by default at `127.0.0.1:3000/graphql`.

## Testing

Expand Down

0 comments on commit e019864

Please sign in to comment.