Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
Hide HERE Map API Key to use with document object

I'm making an express application that requires a map. I'm using the HERE Maps API for javascript boilerplate to render the map. https://developer.here.com/documentation/examples/maps-js

I am already using the dotenv package for environment variables (port, host) in my application. But I don't know how to hide the map API key in the backend when I need to use the document object to render the map. Currently, I'm using a separate file config.js to store the variable but the key is still visible in the frontend.

In conclusion, I can hide the API key in the backend but I can't render the map in the backend and I can render the map in the frontend but I can't hide the API key in the frontend. How can I both hide the API key and render the map?

Minimum, reproducible, example:-

Structure of root directory

| public
    | config.js
    | map.js
| views
    | index.pug
| .env
| index.js
| package.json

index.pug

doctype html
html
    head
        link(rel="stylesheet" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css")
        script(src="https://js.api.here.com/v3/3.1/mapsjs-core.js")
        script(src="https://js.api.here.com/v3/3.1/mapsjs-service.js")
        script(src="https://js.api.here.com/v3/3.1/mapsjs-ui.js")
        script(src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js")
        script(src="config.js" defer)
        script(src="map.js" defer)
    body
        #map(data-lat=lat data-lng=lng)

config.js

const config = {
    MAP_API_KEY: `${API_KEY}`
}

map.js

const mapEl = document.getElementById('map')
const platform = new H.service.Platform({
    apikey: config.MAP_API_KEY
})
const defaultLayers = platform.createDefaultLayers()
const map = new H.Map(mapEl, defaultLayers.vector.normal.map, {
    center: {
        lat: parseFloat(mapEl.dataset.lat),
        lng: parseFloat(mapEl.dataset.lng)
    },
    zoom: 5,
    pixelRatio: window.devicePixelRatio || 1
})
window.addEventListener('resize', () => map.getViewPort().resize())
const behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map))
const ui = H.ui.UI.createDefault(map, defaultLayers)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use headless chrome (puppeteer maybe) which loads only the map, then get a screenshot of it and use the screenshot on your frontend.

You cannot render a map on frontend without an api key. Maybe you should consider restrict api access to specific domain(s)/ip(s) instead.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda