Skip to content

Instantly share code, notes, and snippets.

@chrisbreiding
Created August 31, 2023 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisbreiding/e508acfbfb346a73f2e629a3f75e097c to your computer and use it in GitHub Desktop.
Save chrisbreiding/e508acfbfb346a73f2e629a3f75e097c to your computer and use it in GitHub Desktop.
Less
// servers.js
const express = require('express')
const path = require('path')
const http = require('http')
const httpPorts = [8081, 8082]
// const httpsPorts = []
const createApp = (port) => {
const app = express()
app.set('port', port)
app.set('view engine', 'html')
// app.use(require('cors')())
// app.use(require('cookie-parser')())
// app.use(require('compression')())
// app.use(bodyParser.urlencoded({ extended: false }))
// app.use(bodyParser.json())
// app.use(bodyParser.raw())
// app.use(require('method-override')())
app.get('/', (req, res) => {
return res.send(`<html><body>root page for localhost:${port}</body></html>`)
})
app.use(express.static(path.join(__dirname, '../../html')))
return app
}
const startServers = () => {
httpPorts.forEach((port) => {
const app = createApp(port)
const server = http.Server(app)
return server.listen(app.get('port'), () => {
// eslint-disable-next-line no-console
return console.log('Express server listening on port', app.get('port'))
})
})
// httpsPorts.forEach((port) => {
// const httpsApp = createApp(port)
// const httpsServer = httpsProxy.httpsServer(httpsApp)
// return httpsServer.listen(port, () => {
// // eslint-disable-next-line no-console
// return console.log('Express server listening on port', port, '(HTTPS)')
// })
// })
}
module.exports = {
startServers,
}
// less.html
<!DOCTYPE html>
<head>
<link rel="stylesheet/less" type="text/css" href="styles-variables.less" />
<link rel="stylesheet/less" type="text/css" href="styles.less" />
<script src="https://cdn.jsdelivr.net/npm/less" ></script>
</head>
<body>
<h1>This page uses less css</h1>
</body>
// spec.js
describe('.less loading', () => {
it('pass', () => {
cy.visit('http://localhost:8081/')
cy.origin('http://localhost:8082', () => {
cy.visit('/less.html')
})
})
})
styles.less
html {
background: aqua;
color: darkblue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment